298 Commits
Author SHA1 Message Date
Eric Hawicz befb5a0b26 Merge pull request #961 from dxbjavid/pointer-set-unescape
decode ~1/~0 escapes when setting an object member in json_pointer
2026-08-30 10:22:42 -04:00
Javid Khan dcdea4e906 decode ~1/~0 escapes when setting an object member in json_pointer 2026-08-22 12:01:01 +05:30
Junki Lee 2094974201 Fix object key leak on insertion failure 2026-08-21 13:18:26 +09:00
Max Rijkers 105a1067e3 Use printf instead of echo 2026-08-20 23:21:16 +02:00
Max Rijkers c80ca19a35 Only execute test_json_parse_cli when BUILD_APPS is ON 2026-08-20 23:19:38 +02:00
Javid Khan 510d68bd35 reject negative after whitespace in json_parse_uint64 2026-08-17 20:37:45 +05:30
Eric Hawicz 81092b3072 Merge pull request #948 from thesamesam/meson
meson: wire up `disable_extra_libs` option
2026-08-17 01:16:31 -04:00
Denis Gregor e222189360 Check the whole RFC 8259 number grammar in strict mode
Strict mode rejected leading zeros but nothing else about the shape of a
number, so several malformed numbers parsed and were then written back out
verbatim, producing JSON that other parsers reject:

    $ echo '[2.e3]' | ./json_parse -s -
    [ 2.e3 ]

RFC 8259 requires a mandatory integer part and at least one digit in both the
fraction and the exponent:

    number = [ minus ] int [ frac ] [ exp ]
    int    = zero / ( digit1-9 *DIGIT )
    frac   = decimal-point 1*DIGIT
    exp    = e [ minus / plus ] 1*DIGIT

so "1.", "-2.", "2.e3", "2.e+3", "0.e1", "-.123", "1e" and "1e+" are all
invalid. Walk the accumulated text against that grammar instead. The leading
zero rule from the previous check is part of the same walk rather than a
separate test, and its cases keep their coverage.

Only JSON_TOKENER_STRICT is affected; the default tokener stays as lenient as
it was. Measured against JSONTestSuite (318 files): strict mode went from 44
to 37 files accepted that the suite says must be rejected, default mode stayed
at 71, and nothing that must be accepted regressed in either mode.
2026-08-16 20:26:15 +03:00
Eric Hawicz 892c204ce0 Merge pull request #955 from carrerasdarren-cell/agent/fix-printbuf-self-append
printbuf: preserve self-append sources across growth
2026-08-15 10:10:20 -04:00
Darren Carreras 9782370c3f Address printbuf review comments 2026-08-09 20:01:12 -04:00
Darren Carreras 62bb838c57 printbuf: preserve self-append sources across growth
When the appended data points into the printbuf itself, growing the buffer may invalidate the source pointer before it is copied. Preserve the source offset across realloc and use memmove for internal overlap.
2026-08-01 14:12:56 -04:00
Javid Khan ff18c75286 reject leading zeros in strict-mode number parsing 2026-07-28 13:27:25 +05:30
Sam James 87087ded64 meson: improve test handling
Tests will now be built at `meson test`-time, so there's no cost if the
user isn't going to run them.

This is better than guarding on build type, as distros may want to test production
builds before shipping.

Signed-off-by: Sam James <sam@gentoo.org>
2026-07-24 07:37:41 +01:00
Javid Khan 70f3169bae reject empty reference token as array index in json_pointer 2026-07-20 14:44:51 +05:30
Javid Khan e248056aa1 require string type for patch op/path/from fields 2026-07-18 21:08:17 +05:30
Javid Khan eed664e06a reject null op/path/from fields in json_patch_apply 2026-07-16 12:55:41 +05:30
Eric Hawicz 0ea5f6c615 Merge pull request #942 from dxbjavid/strerror-negative-oob
fix out-of-bounds read for negative errno in _json_c_strerror
2026-07-16 00:42:42 -04:00
Arran Cudbard-Bell 69be99ef8e fix json_object_put() to return 1 for freed scalars and empty containers
The iterative rewrite in 17328a67 made json_object_put() return 0 for freed scalars, strings and empty containers, contradicting the documented contract in json_object.h. Distinguish "freed" from "still referenced" in _json_object_put_maybe_free() and add regression tests.
2026-07-14 10:28:04 -04:00
Javid Khan 9d116a5d38 fix out-of-bounds read for negative errno in _json_c_strerror 2026-07-13 13:46:36 +05:30
Javid Khan 16e394ba96 reject out-of-range double in get_int64/get_uint64 2026-07-06 18:07:09 +05:30
Eric Hawicz 324e5ca593 Merge pull request #933 from dxbjavid/int-inc-int64min-overflow
fix signed overflow negating INT64_MIN in json_object_int_inc
2026-07-04 11:40:42 -04:00
Eric Hawicz 0c3a5a1994 Issue #934: Also set _userdata=NULL in _json_object_maybe_free() so json_object_put doesn't try to use it as a _delete_parent value.
Update the test_deep_nesting test output.
2026-07-04 11:39:02 -04:00
Eric Hawicz 3aa996b5b6 Issue #934: Be sure to clear _user_delete in _json_object_put_maybe_free() to avoid calling it twice. Add a test to check. 2026-07-04 11:02:06 -04:00
Javid Khan 54f5526011 fix signed overflow negating INT64_MIN in json_object_int_inc 2026-06-27 22:52:43 +05:30
dxbjavid 5647679c0c deep copy values in json_patch copy op to avoid aliasing and cycles 2026-06-24 21:56:36 +05:30
Eric Hawicz cce075f551 Merge pull request #930 from dxbjavid/get-double-locale-radix
fix locale-dependent strtod in json_object_get_double
2026-06-21 19:46:36 -04:00
Eric Hawicz d9d8cab822 Add tests for the json_parse cli tool. 2026-06-21 13:44:59 -04:00
Eric Hawicz bb9c1238ad Save stderr from test output, allow for non-zero exit code from tests. 2026-06-21 13:43:11 -04:00
dxbjavid c6cd1f236c fix locale-dependent strtod in json_object_get_double 2026-06-15 23:53:53 +05:30
Eric Hawicz d1018cf6ba Update test_object_iterator.expect to match current test output. 2026-05-25 15:27:48 -04:00
Eric Hawicz 6167807f3a Merge pull request #925 from mbroz/fix-build
Fix build with clang-21
2026-05-24 16:07:11 -04:00
Eric Hawicz dee128f4d6 Issue #927: update the documentation for json_object_iterator to clarify that any change of the fields present on the object being iterated invalidates the iterator.
Update the test to show what kind of changes _are_ allowed.
2026-05-23 14:31:45 -04:00
Eric Hawicz 79474075ce Fix expected output for test_deep_nesting 2026-05-23 14:31:45 -04:00
Milan Broz 1f7589fa2f Fix function prototypes in deep nesting test (clang compilation)
This patch fixes the build error with clang-21
  tests/test_deep_nesting.c:19:34: error: a function declaration
  without a prototype is deprecated in all versions of C
  [-Werror,-Wstrict-prototypes]
   19 | static char *generate_json_string()

by fixing generate_json_string() definition.

It also removes prototypes for static functions that are not needed.
2026-05-12 21:46:50 +02:00
Eric Hawicz 5320cf9753 Add a test to check for issues with deeply nested objects, which can cause problems due to stack recursion. 2026-05-03 20:44:02 -04:00
Eric Hawicz 52ddfb35f1 Fix memory leak in test_safe_json_pointer_set, the caller must free the passed value when json_pointer_set failed. Also, reformat. 2026-02-19 19:05:10 -05:00
Eric Hawicz d7f14cb330 Merge pull request #917 from thely314/fix/oom-too-large-index
Fix: OOM vulnerability cause by is_valid_index
2026-02-14 17:23:49 -05:00
lone c293d9b61c general callback, safer API & related tests
- Changed json_pointer_set_with_array_cb to json_pointer_set_with_cb, related cb updated
- Added tests(test_safe_json_pointer_set.*) for new-exported funcs, also updated cmake & meson

Signed-off-by: lone <lonechan314@qq.com>
2026-02-09 14:01:38 +08:00
Rosen Penev 92a4911e88 meson: use static library for tests
Needed as tests use private APIs that are not exported.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2026-02-05 13:46:00 -08:00
Timothée Ravier e4b9dfba49 tests/CMakeLists: Allow build with CMake 4
See: https://github.com/json-c/json-c/issues/889
2025-12-23 11:52:43 +01:00
Tyler Erickson 3723b182db bug: Fixing runtime issue with test_util_file.c in Windows
Windows was failing tests due to how the Windows API works with some of the calls used.
When opening and reading a file O_BINARY is needed otherwise it fails for size checks. This is due to how Windows handles newlines and counts between text and binary mode file reads.

Also fixed is the test for /dev/null.
In Windows, this fails, but crashes due to a missing return statement when it cannot open this file.
I also tried telling windows to open the special file NUL, however that leads to a CRT crash later in the test that cannot be stopped and will always fail. Rather than fail a test that Windows will always fail, it has been disabled in that specific case.

Signed-off-by: Tyler Erickson <tyler.erickson@seagate.com>
2025-10-20 12:10:57 -06:00
Tyler Erickson e3a33ae8ae make: Adding support for building json-c with meson
Adding meson build files for json-c that work similarly to the cmake build files.
Where it made sense, I reused existing cmake .h.in files or generated entirely from meson.
All tests were done with GCC and Clang in ubuntu 24.04, Windows using MSVC 2022 and Clang-cl from llvm's repo using version 21.1.3

Signed-off-by: Tyler Erickson <tyler.erickson@seagate.com>
2025-10-20 12:08:01 -06:00
Shane F. Carr 7974657c56 Fix code and update tests 2025-07-30 17:40:56 -07:00
Shane F. Carr dbefb48948 Add tests with current behavior 2025-07-30 17:39:47 -07:00
Eric Hawicz 7cee5237dc Issue #867 - also disallow control characters in keys 2025-04-03 21:16:29 -04:00
Simon Resch 0c3588330a Set error codes for truncating int conversions
json_object_get_int/int64/uint64() now sets errno to ERANGE when the source value
can't be represented in the target type.
2024-11-27 07:17:20 +01:00
Simon Resch 8c13801f2c Explicitly handle NaN values when converting to int
Json objects of type double with the value NaN could cause undefined
behavior when casting double to int in `json_object_get_int`.
2024-11-27 07:17:20 +01:00
Eric Hawicz 565f181f65 Fix issue #875: cast to unsigned char so bytes above 0x7f aren't interpreted as negative, which was causing the strict-mode control characters check to incorrectly trigger. 2024-11-08 22:20:40 -05:00
Eric Hawicz 87900c0a2e Fix the expected output for test_parse 2024-09-15 11:59:05 -04:00
Eric Hawicz 6bfab90c87 Issue #867: disallow control characters in strict mode. 2024-09-15 10:37:45 -04:00