Skip to content

Commit

Permalink
Fix potential out of bound substr access
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Jan 12, 2016
1 parent e927e2c commit abbcddb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2624,8 +2624,10 @@ namespace Sass {

std::string left(pos_left, end_left);
std::string right(pos_right, end_right);
if (ellipsis_left) left = ellipsis + left.substr(left.size() - 15);
if (ellipsis_right) right = right.substr(right.size() - 15) + ellipsis;
size_t left_subpos = left.size() > 15 ? left.size() - 15 : 0;
size_t right_subpos = right.size() > 15 ? right.size() - 15 : 0;
if (left_subpos && ellipsis_left) left = ellipsis + left.substr(left_subpos);
if (right_subpos && ellipsis_right) right = right.substr(right_subpos) + ellipsis;
// now pass new message to the more generic error function
error(msg + prefix + quote(left) + middle + quote(right), pstate);
}
Expand Down

0 comments on commit abbcddb

Please sign in to comment.