From 1934059554b9a0971e00f79e96900f422cfdd114 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Thu, 23 Mar 2017 21:35:24 +0100 Subject: [PATCH] ensure: Validate buffer offset --- cJSON.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cJSON.c b/cJSON.c index 8c0e9325..792744bf 100644 --- a/cJSON.c +++ b/cJSON.c @@ -253,6 +253,12 @@ static unsigned char* ensure(printbuffer * const p, size_t needed, const interna return NULL; } + if ((p->length > 0) && (p->offset >= p->length)) + { + /* make sure that offset is valid */ + return NULL; + } + if (needed > INT_MAX) { /* sizes bigger than INT_MAX are currently not supported */