From: Vsevolod Stakhov Date: Sat, 12 Jan 2013 13:38:21 +0000 (+0400) Subject: Do not panic when json buffer is NULL or empty. X-Git-Tag: 0.5.4~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6165ab1a40624aff8627b89db4115844d485d3d1;p=thirdparty%2Frspamd.git Do not panic when json buffer is NULL or empty. --- diff --git a/src/json/load.c b/src/json/load.c index 0f0968e9e1..45ff45d678 100644 --- a/src/json/load.c +++ b/src/json/load.c @@ -795,6 +795,11 @@ json_loads (const char *string, json_error_t * error) .pos = 0 }; + if (string == NULL || *string == '\0') { + error_set (error, NULL, "empty stream"); + return NULL; + } + if (lex_init (&lex, string_get, string_eof, (void *)&stream_data)) return NULL; @@ -892,6 +897,11 @@ json_load_evbuffer (struct evbuffer *evb, json_error_t *error) lex_t lex; json_t *result; + if (evb == NULL || EVBUFFER_LENGTH (evb) == 0) { + error_set (error, NULL, "empty stream"); + return NULL; + } + stream_data.data = EVBUFFER_DATA (evb); stream_data.pos = 0; stream_data.len = EVBUFFER_LENGTH (evb);