Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <stdint.h>

#ifdef ENABLE_LOCALES
#include <locale.h>
Expand Down Expand Up @@ -394,6 +395,11 @@ static unsigned char* ensure(printbuffer * const p, size_t needed)
return NULL;
}

/* Ensure adding (p->offset + 1) won't overflow SIZE_MAX */
if (p->offset > SIZE_MAX - 1 - needed) {
return NULL;
}

needed += p->offset + 1;
if (needed <= p->length)
{
Expand Down