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
25 changes: 13 additions & 12 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,24 +442,25 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
{
return NULL;
}
/* return NULL if the object is corrupted or valuestring is NULL */
if (object->valuestring == NULL || valuestring == NULL)
/* return NULL if valuestring is NULL */
if (valuestring == NULL)
{
return NULL;
}

v1_len = strlen(valuestring);
v2_len = strlen(object->valuestring);

if (v1_len <= v2_len)
if(object->valuestring)
{
/* strcpy does not handle overlapping string: [X1, X2] [Y1, Y2] => X2 < Y1 or Y2 < X1 */
if (!( valuestring + v1_len < object->valuestring || object->valuestring + v2_len < valuestring ))
v1_len = strlen(valuestring);
v2_len = strlen(object->valuestring);

if (v1_len <= v2_len)
{
return NULL;
/* strcpy does not handle overlapping string: [X1, X2] [Y1, Y2] => X2 < Y1 or Y2 < X1 */
if ( valuestring + v1_len < object->valuestring || object->valuestring + v2_len < valuestring )
{
strcpy(object->valuestring, valuestring);
return object->valuestring;
}
}
strcpy(object->valuestring, valuestring);
return object->valuestring;
}
copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks);
if (copy == NULL)
Expand Down