Skip to content
Myr

Heap buffer overflow in tokenadd() (fix #105)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This was an off-by one: the NUL terminator byte was not allocated on resize. This was triggered by JSON-encoded numbers longer than 256 bytes.

authored by Nicolas Williams · committed by Nicolas Williams · parent 2f79004 · Browse files · 1 file+2 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−2 removed

  • other:+2 added−2 removed

1 file+2 added−2 removed

modified:src/jv_parse.c+2 added-2 removed
381 unmodified lines
382}383384static void tokenadd(struct jv_parser* p, char c) {385 assert(p->tokenpos <= p->tokenlen);386 if (p->tokenpos == p->tokenlen) {386 if (p->tokenpos >= (p->tokenlen - 1)) {387 p->tokenlen = p->tokenlen*2 + 256;388 p->tokenbuf = jv_mem_realloc(p->tokenbuf, p->tokenlen);389 }390 assert(p->tokenpos < p->tokenlen);
93 unmodified lines
484 return "Invalid literal";485 TRY(value(p, v));486 } else {487 // FIXME: better parser488 p->tokenbuf[p->tokenpos] = 0; // FIXME: invalid488 p->tokenbuf[p->tokenpos] = 0;489 char* end = 0;490 double d = jvp_strtod(&p->dtoa, p->tokenbuf, &end);491 if (end == 0 || *end != 0)492 return "Invalid numeric literal";
360 unmodified lines