From 53e9dd848f924021ec60ab3cd21c0c87c9dce37c Mon Sep 17 00:00:00 2001 From: allen Date: Mon, 16 Sep 2019 15:50:59 +0800 Subject: [PATCH] add the loop key length macro for circular reference detect --- src/dump.c | 3 +-- src/jansson_private.h | 2 ++ src/value.c | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/dump.c b/src/dump.c index 5285d43..b57282f 100644 --- a/src/dump.c +++ b/src/dump.c @@ -296,8 +296,7 @@ static int do_dump(const json_t *json, size_t flags, int depth, void *iter; const char *separator; int separator_length; - /* Space for "0x", double the sizeof a pointer for the hex and a terminator. */ - char loop_key[2 + (sizeof(json) * 2) + 1]; + char loop_key[LOOP_KEY_LEN]; if(flags & JSON_COMPACT) { separator = ":"; diff --git a/src/jansson_private.h b/src/jansson_private.h index 2da33d5..c7ce11a 100644 --- a/src/jansson_private.h +++ b/src/jansson_private.h @@ -91,6 +91,8 @@ char *jsonp_strdup(const char *str) JANSSON_ATTRS(warn_unused_result); char *jsonp_strndup(const char *str, size_t len) JANSSON_ATTRS(warn_unused_result); /* Circular reference check*/ +/* Space for "0x", double the sizeof a pointer for the hex and a terminator. */ +#define LOOP_KEY_LEN (2 + (sizeof(json_t *) * 2) + 1) int jsonp_loop_check(hashtable_t *parents, const json_t *json, char *key, size_t key_size); diff --git a/src/value.c b/src/value.c index 9ec75ee..7a000f8 100644 --- a/src/value.c +++ b/src/value.c @@ -322,10 +322,10 @@ static json_t *json_object_deep_copy(const json_t *object, hashtable_t *parents) { json_t *result; void *iter; - char loop_key[2 + (sizeof(object) * 2) + 1]; + char loop_key[LOOP_KEY_LEN]; if (jsonp_loop_check(parents, object, loop_key, sizeof(loop_key))) - return NULL; + return NULL; result = json_object(); if(!result) @@ -641,7 +641,7 @@ static json_t *json_array_deep_copy(const json_t *array, hashtable_t *parents) { json_t *result; size_t i; - char loop_key[2 + (sizeof(array) * 2) + 1]; + char loop_key[LOOP_KEY_LEN]; if (jsonp_loop_check(parents, array, loop_key, sizeof(loop_key))) return NULL;