Skip to content

Commit

Permalink
Fix bad usage of strncat introduces in 1a94c70. Pointed out by @rouault
Browse files Browse the repository at this point in the history
… in PR json-c#331.
  • Loading branch information
hawicz committed Jul 9, 2017
1 parent 55ecae3 commit 7b7a76e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions json_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,11 @@ static int json_object_double_to_json_string_format(struct json_object* jso,
if (!format)
format = std_format;
size = snprintf(buf, sizeof(buf), format, jso->o.c_double);
if (modf(jso->o.c_double, &dummy) == 0)
if (modf(jso->o.c_double, &dummy) == 0 && size >= 0 && size < (int)sizeof(buf) - 2)
{
// Ensure it looks like a float, even if snprintf didn't.
strncat(buf, ".0", sizeof(buf) - 1);
if (size >= 0)
size += 2; // yes, even if strncat ran out of room
strcat(buf, ".0");
size += 2;
}
}
// although unlikely, snprintf can fail
Expand Down

0 comments on commit 7b7a76e

Please sign in to comment.