]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Fix read past end of buffer 655/head
authorMarc <34656315+MarcT512@users.noreply.github.com>
Fri, 7 Aug 2020 09:49:45 +0000 (10:49 +0100)
committerGitHub <noreply@github.com>
Fri, 7 Aug 2020 09:49:45 +0000 (10:49 +0100)
Resolves https://github.com/json-c/json-c/issues/654

apps/json_parse.c

index bba462218396808bc44454f213b44c36aee7705a..72b31a860a2bcb34d2f6d9df79068083428d2025 100644 (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,