From dec906196dc53e4aaa2937d1e57a8b3761a1b531 Mon Sep 17 00:00:00 2001 From: panggou Date: Tue, 9 Mar 2021 11:11:59 +0800 Subject: [PATCH] =?UTF-8?q?[Huawei]=E5=AE=89=E5=85=A8=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=80=89=E9=A1=B9=EF=BC=8C=E9=80=82=E9=85=8D=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Offering: GaussDB Kernel Signed-off-by: jiangjiangjun@huawei.com --- Makefile | 4 ++-- cJSON.c | 18 +++++++++--------- cJSON.h | 1 + 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 4e727b7..1ee5a21 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,8 @@ LIBVERSION = 1.7.13 CJSON_SOVERSION = 1 UTILS_SOVERSION = 1 -CJSON_SO_LDFLAG=-Wl,-soname=$(CJSON_LIBNAME).so.$(CJSON_SOVERSION) -UTILS_SO_LDFLAG=-Wl,-soname=$(UTILS_LIBNAME).so.$(UTILS_SOVERSION) +CJSON_SO_LDFLAG=-Wl,-z,relro,-z,now,-soname=$(CJSON_LIBNAME).so.$(CJSON_SOVERSION) +UTILS_SO_LDFLAG=-Wl,-z,relro,-z,now,-soname=$(UTILS_LIBNAME).so.$(UTILS_SOVERSION) PREFIX ?= /usr/local INCLUDE_PATH ?= include/cjson diff --git a/cJSON.c b/cJSON.c index a5d3987..27c9388 100644 --- a/cJSON.c +++ b/cJSON.c @@ -181,7 +181,7 @@ static void * CJSON_CDECL internal_realloc(void *pointer, size_t size) static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc }; -static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) +CJSON_PUBLIC(unsigned char*) cJSON_strdup(const unsigned char* string) { size_t length = 0; unsigned char *copy = NULL; @@ -192,7 +192,7 @@ static unsigned char* cJSON_strdup(const unsigned char* string, const internal_h } length = strlen((const char*)string) + sizeof(""); - copy = (unsigned char*)hooks->allocate(length); + copy = (unsigned char*)global_hooks.allocate(length); if (copy == NULL) { return NULL; @@ -406,7 +406,7 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring) strcpy(object->valuestring, valuestring); return object->valuestring; } - copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks); + copy = (char*) cJSON_strdup((const unsigned char*)valuestring); if (copy == NULL) { return NULL; @@ -2020,7 +2020,7 @@ static cJSON_bool add_item_to_object(cJSON * const object, const char * const st } else { - new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); + new_key = (char*)cJSON_strdup((const unsigned char*)string); if (new_key == NULL) { return false; @@ -2341,7 +2341,7 @@ static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSO { cJSON_free(replacement->string); } - replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + replacement->string = (char*)cJSON_strdup((const unsigned char*)string); replacement->type &= ~cJSON_StringIsConst; return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); @@ -2434,7 +2434,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) if(item) { item->type = cJSON_String; - item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + item->valuestring = (char*)cJSON_strdup((const unsigned char*)string); if(!item->valuestring) { cJSON_Delete(item); @@ -2484,7 +2484,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) if(item) { item->type = cJSON_Raw; - item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); + item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw); if(!item->valuestring) { cJSON_Delete(item); @@ -2686,7 +2686,7 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) newitem->valuedouble = item->valuedouble; if (item->valuestring) { - newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); + newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring); if (!newitem->valuestring) { goto fail; @@ -2694,7 +2694,7 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) } if (item->string) { - newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); + newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string); if (!newitem->string) { goto fail; diff --git a/cJSON.h b/cJSON.h index 0c6c8e0..4481dfd 100644 --- a/cJSON.h +++ b/cJSON.h @@ -286,6 +286,7 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring) CJSON_PUBLIC(void *) cJSON_malloc(size_t size); CJSON_PUBLIC(void) cJSON_free(void *object); +CJSON_PUBLIC(unsigned char*) cJSON_strdup(const unsigned char* string); #ifdef __cplusplus } #endif -- 2.23.0