Skip to content

Commit 89723b6

Browse files
authored
Merge pull request #2353 from mgreter/bugfix/issue-2352
Fix segfault for varargs with non-string keys
2 parents 3c37826 + 02b94d8 commit 89723b6

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

src/bind.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,17 @@ namespace Sass {
9595
env->local_frame()[p->name()] = arglist;
9696
Map_Obj argmap = Cast<Map>(a->value());
9797
for (auto key : argmap->keys()) {
98-
std::string param = unquote(Cast<String_Constant>(key)->value());
99-
arglist->append(SASS_MEMORY_NEW(Argument,
100-
key->pstate(),
101-
argmap->at(key),
102-
"$" + param,
103-
false,
104-
false));
98+
if (String_Constant_Obj str = Cast<String_Constant>(key)) {
99+
std::string param = unquote(str->value());
100+
arglist->append(SASS_MEMORY_NEW(Argument,
101+
key->pstate(),
102+
argmap->at(key),
103+
"$" + param,
104+
false,
105+
false));
106+
} else {
107+
throw Exception::InvalidVarKwdType(key->pstate(), key->inspect(), a);
108+
}
105109
}
106110

107111
} else {

src/error_handling.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ namespace Sass {
3131
msg += "\"";
3232
}
3333

34+
InvalidVarKwdType::InvalidVarKwdType(ParserState pstate, std::string name, const Argument_Ptr arg)
35+
: Base(pstate), name(name), arg(arg)
36+
{
37+
msg = "Variable keyword argument map must have string keys.\n";
38+
msg += name + " is not a string in " + arg->to_string() + ".";
39+
}
40+
3441
InvalidArgumentType::InvalidArgumentType(ParserState pstate, std::string fn, std::string arg, std::string type, const Value_Ptr value)
3542
: Base(pstate), fn(fn), arg(arg), type(type), value(value)
3643
{

src/error_handling.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ namespace Sass {
6868
virtual ~InvalidArgumentType() throw() {};
6969
};
7070

71+
class InvalidVarKwdType : public Base {
72+
protected:
73+
std::string name;
74+
const Argument_Ptr arg;
75+
public:
76+
InvalidVarKwdType(ParserState pstate, std::string name, const Argument_Ptr arg = 0);
77+
virtual ~InvalidVarKwdType() throw() {};
78+
};
79+
7180
class InvalidSyntax : public Base {
7281
public:
7382
InvalidSyntax(ParserState pstate, std::string msg, std::vector<Sass_Import_Entry>* import_stack = 0);

0 commit comments

Comments
 (0)