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