]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Merge pull request #759 from c3h2-ctf/truncation
authorEric Hawicz <erh+git@nimenees.com>
Tue, 4 Jul 2023 15:45:57 +0000 (11:45 -0400)
committerGitHub <noreply@github.com>
Tue, 4 Jul 2023 15:45:57 +0000 (11:45 -0400)
json_tokener_parse_ex: handle out of memory errors

1  2 
json_tokener.c

diff --cc json_tokener.c
index 753d4f22c9b49be7f3f9772c42d4d81201627ac6,af03a857803bd20536fc99a8876a222c0c69d172..25f41dcbaf0394cca5405d3f833cebea69823c05
@@@ -992,14 -1030,12 +1031,17 @@@ struct json_object *json_tokener_parse_
                                if (!tok->is_double && tok->pb->buf[0] == '-' &&
                                    json_parse_int64(tok->pb->buf, &num64) == 0)
                                {
 +                                      if (errno == ERANGE && (tok->flags & JSON_TOKENER_STRICT))
 +                                      {
 +                                              tok->err = json_tokener_error_parse_number;
 +                                              goto out;
 +                                      }
                                        current = json_object_new_int64(num64);
                                        if (current == NULL)
+                                       {
+                                               tok->err = json_tokener_error_memory;
                                                goto out;
+                                       }
                                }
                                else if (!tok->is_double && tok->pb->buf[0] != '-' &&
                                         json_parse_uint64(tok->pb->buf, &numuint64) == 0)