Skip to content

Commit

Permalink
config: fix possible out-of-bound access in parsing function
Browse files Browse the repository at this point in the history
Add low-bound check when decreasing string pointer from tail.
  • Loading branch information
Baofeng Wang authored and sirainen committed May 19, 2016
1 parent 81f0bc1 commit dca0719
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/config/config-parser.c
Expand Up @@ -595,17 +595,25 @@ config_parse_line(struct config_parser_context *ctx,

/* remove whitespace from end of line */
len = strlen(line);
while (IS_WHITE(line[len-1]))
while (len >= 1) {
if(!IS_WHITE(line[len-1]))
break;
len--;
}
line[len] = '\0';

if (len > 0 && line[len-1] == '\\') {
if (len >= 1 && line[len-1] == '\\') {
/* continues in next line */
len--;
while (IS_WHITE(line[len-1]))
while (len >= 1) {
if(!IS_WHITE(line[len-1]))
break;
len--;
str_append_n(full_line, line, len);
str_append_c(full_line, ' ');
}
if(len >= 1) {
str_append_n(full_line, line, len);
str_append_c(full_line, ' ');
}
return CONFIG_LINE_TYPE_CONTINUE;
}
if (str_len(full_line) > 0) {
Expand Down

0 comments on commit dca0719

Please sign in to comment.