You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.2 KiB

  1. From 8eb1367ca44e772963e704a700ef72ae2e12babd Mon Sep 17 00:00:00 2001
  2. From: Nicolas Williams <nico@cryptonector.com>
  3. Date: Sat, 24 Oct 2015 17:24:57 -0500
  4. Subject: [PATCH] Heap buffer overflow in tokenadd() (fix #105)
  5. This was an off-by one: the NUL terminator byte was not allocated on
  6. resize. This was triggered by JSON-encoded numbers longer than 256
  7. bytes.
  8. ---
  9. src/jv_parse.c | 4 ++--
  10. 1 file changed, 2 insertions(+), 2 deletions(-)
  11. diff --git a/src/jv_parse.c b/src/jv_parse.c
  12. index 3102ed4..84245b8 100644
  13. --- src/jv_parse.c
  14. +++ src/jv_parse.c
  15. @@ -383,7 +383,7 @@ static pfunc stream_token(struct jv_parser* p, char ch) {
  16. static void tokenadd(struct jv_parser* p, char c) {
  17. assert(p->tokenpos <= p->tokenlen);
  18. - if (p->tokenpos == p->tokenlen) {
  19. + if (p->tokenpos >= (p->tokenlen - 1)) {
  20. p->tokenlen = p->tokenlen*2 + 256;
  21. p->tokenbuf = jv_mem_realloc(p->tokenbuf, p->tokenlen);
  22. }
  23. @@ -485,7 +485,7 @@ static pfunc check_literal(struct jv_parser* p) {
  24. TRY(value(p, v));
  25. } else {
  26. // FIXME: better parser
  27. - p->tokenbuf[p->tokenpos] = 0; // FIXME: invalid
  28. + p->tokenbuf[p->tokenpos] = 0;
  29. char* end = 0;
  30. double d = jvp_strtod(&p->dtoa, p->tokenbuf, &end);
  31. if (end == 0 || *end != 0)