From 22dee7cb59da4a96fe2ee0e33b4f394645698359 Mon Sep 17 00:00:00 2001 From: Michael Clark Date: Wed, 25 Feb 2009 01:51:40 +0000 Subject: [PATCH] * Null pointer dereference fix. Fix json_object_get_boolean strlen test to not return TRUE for zero length string. Remove redundant includes. Erik Hovland, erik at hovland dot org git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@31 327403b1-1117-474d-bef2-5cb71233fd97 --- ChangeLog | 3 +++ arraylist.c | 2 +- json_object.c | 3 +-- json_tokener.c | 3 +++ linkhash.c | 2 -- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e8f0d35..2009a1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ 0.9 + * Null pointer dereference fix. Fix json_object_get_boolean strlen test + to not return TRUE for zero length string. Remove redundant includes. + Erik Hovland, erik at hovland dot org * Fixed warning reported by adding -Wstrict-prototypes -Wold-style-definition to the compilatin flags. Dotan Barak, dotanba at gmail dot com diff --git a/arraylist.c b/arraylist.c index dbd075d..bc167a8 100644 --- a/arraylist.c +++ b/arraylist.c @@ -16,7 +16,7 @@ # include #endif /* STDC_HEADERS */ -#if HAVE_STRINGS_H +#if defined HAVE_STRINGS_H && !defined _STRING_H && !defined __USE_BSD # include #endif /* HAVE_STRINGS_H */ diff --git a/json_object.c b/json_object.c index a746859..44b6cd6 100644 --- a/json_object.c +++ b/json_object.c @@ -22,7 +22,6 @@ #include "arraylist.h" #include "json_object.h" #include "json_object_private.h" -#include "json_tokener.h" #if !HAVE_STRNDUP char* strndup(const char* str, size_t n); @@ -306,7 +305,7 @@ boolean json_object_get_boolean(struct json_object *this) case json_type_double: return (this->o.c_double != 0); case json_type_string: - if(strlen(this->o.c_string)) return TRUE; + return (strlen(this->o.c_string) != 0); default: return TRUE; } diff --git a/json_tokener.c b/json_tokener.c index 3f196db..9c05728 100644 --- a/json_tokener.c +++ b/json_tokener.c @@ -83,6 +83,9 @@ static void json_tokener_reset_level(struct json_tokener *tok, int depth) void json_tokener_reset(struct json_tokener *tok) { int i; + if (!tok) + return; + for(i = tok->depth; i >= 0; i--) json_tokener_reset_level(tok, i); tok->depth = 0; diff --git a/linkhash.c b/linkhash.c index 5d4e46f..7385401 100644 --- a/linkhash.c +++ b/linkhash.c @@ -9,8 +9,6 @@ * */ -#include "config.h" - #include #include #include