Skip to content

Commit

Permalink
Fix parsing to not skip NUL characters
Browse files Browse the repository at this point in the history
Fix multiple instances of the parser skipping a NUL character, causing a
buffer over-read and possibly crash.
  • Loading branch information
mlichvar committed Apr 13, 2022
1 parent 6f5531d commit 391bfcb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions nvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,11 @@ struct nvp *make_nvp(struct msg_src *src, char *s, const char *pfx)/*{{{*/
case GOT_NAMEVALUE_CCONT:
for(tempsrc = tempdst = value; *tempsrc; tempsrc++) {
if (*tempsrc == '%') {
int val = hex_to_val(*++tempsrc) << 4;
val |= hex_to_val(*++tempsrc);
int val = -1;
if (tempsrc[1] && tempsrc[2]) {
val = hex_to_val(*++tempsrc) << 4;
val |= hex_to_val(*++tempsrc);
}
if (val < 0) {
#ifdef TEST
fprintf(stderr, "'%s' could not be parsed (%%)\n", s);
Expand Down
6 changes: 3 additions & 3 deletions rfc822.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ static time_t parse_rfc822_date(char *date_string)/*{{{*/
else if (!strncasecmp(s, "dec", 3)) tm.tm_mon = 11;
else goto tough_cheese;

while (!isspace(*s)) s++;
while (*s && !isspace(*s)) s++;
while (*s && isspace(*s)) s++;
if (!isdigit(*s)) goto tough_cheese;
tm.tm_year = atoi(s);
Expand Down Expand Up @@ -1056,9 +1056,9 @@ struct rfc822 *data_to_rfc822(struct msg_src *src,
else if (!result->hdrs.references && match_string("references:", x->text))
result->hdrs.references = copy_header_value(x->text);
else if (match_string("status:", x->text))
scan_status_flags(x->text + sizeof("status:"), &result->hdrs);
scan_status_flags(x->text + (sizeof("status:") - 1), &result->hdrs);
else if (match_string("x-status:", x->text))
scan_status_flags(x->text + sizeof("x-status:"), &result->hdrs);
scan_status_flags(x->text + (sizeof("x-status:") - 1), &result->hdrs);
}
/*}}}*/

Expand Down

0 comments on commit 391bfcb

Please sign in to comment.