Skip to content

Commit 980e17d

Browse files
committed
Protect map from accessing illegal keys
1 parent 8e1da10 commit 980e17d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

ast.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
namespace Sass {
99
using namespace std;
1010

11+
static Null sass_null(Sass::Null(ParserState("null")));
12+
1113
bool Compound_Selector::operator<(const Compound_Selector& rhs) const
1214
{
1315
To_String to_string;
@@ -587,5 +589,12 @@ namespace Sass {
587589
return result;
588590
}*/
589591

592+
Expression* Hashed::at(Expression* k) const
593+
{
594+
if (elements_.count(k))
595+
{ return elements_.at(k); }
596+
else { return &sass_null; }
597+
}
598+
590599
}
591600

ast.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,10 @@ namespace Sass {
210210
size_t length() const { return list_.size(); }
211211
bool empty() const { return list_.empty(); }
212212
bool has(Expression* k) const { return elements_.count(k) == 1; }
213-
Expression* at(Expression* k) const { return elements_.at(k); }
213+
Expression* at(Expression* k) const;
214214
bool has_duplicate_key() const { return duplicate_key_ != 0; }
215215
Expression* get_duplicate_key() const { return duplicate_key_; }
216+
const unordered_map<Expression*, Expression*> elements() { return elements_; }
216217
Hashed& operator<<(pair<Expression*, Expression*> p)
217218
{
218219
reset_hash();

0 commit comments

Comments
 (0)