Fix read past end of buffer

Resolves https://github.com/json-c/json-c/issues/654
This commit is contained in:
Marc
2020-08-07 10:49:45 +01:00
committed by GitHub
parent 730e3d044f
commit 4e9e44e525

View File

@@ -82,7 +82,8 @@ static int parseit(int fd, int (*callback)(struct json_object *))
int parse_end = json_tokener_get_parse_end(tok);
if (obj == NULL && jerr != json_tokener_continue)
{
char *aterr = &buf[start_pos + parse_end];
char *aterr = (start_pos + parse_end < sizeof(buf)) ?
&buf[start_pos + parse_end] : "";
fflush(stdout);
int fail_offset = total_read - ret + start_pos + parse_end;
fprintf(stderr, "Failed at offset %d: %s %c\n", fail_offset,