Commit Graph
287 Commits
Author SHA1 Message Date
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 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
Rosen Penev 66f7869219 rename WIN32 to _WIN32
The latter is the proper macro defined by Windows headers.

Fixes compilation under at least clang-cl which mandates function
declarations.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2024-02-07 18:06:55 -08:00
Rolf Eike Beer 159822dd8a CMake: request consistent minimum version 2023-09-05 14:31:14 +02:00
Eric Hawicz 469bc0e4bb Work around a somewhat misleading warning about "a function declaration without a prototype is deprecated in all versions of C" in test1.c 2023-07-31 22:18:04 -04:00
Eric Hawicz ce3184243a Fix json_patch_apply handling of removing the whole document (i.e. "path":"").
Enable all disabled tests, add a few more including some with null documents.
2023-07-31 22:18:04 -04:00
Eric Hawicz 9dbf2880cc Adjust the behavior of the args passed to json_patch_apply to make it easier to do in place modifications, and add a struct json_patch_error to report more details on failures. 2023-07-31 22:18:04 -04:00
Eric Hawicz efc530594b Create a json_pointer_private.h and move a few things there, fix test warnings, note array_list_insert_idx is private. 2023-07-31 22:18:03 -04:00
Alexandru Ardelean 3b8363fcdc tests: test_json_patch: add test suite for JSON patch
Essentially, this change adds the test cases from this repo:
   https://github.com/json-patch/json-patch-tests

Specifically:
   https://github.com/json-patch/json-patch-tests/blob/master/spec_tests.json
   https://github.com/json-patch/json-patch-tests/blob/master/tests.json

The files were taken at the date of this commit, at git hash
  ea3af85790cb72893d0676597814b7532019c24e

Some tests may not have an 'expected' or 'error' field. Those are ignored.
One test was disabled manually via "disabled_in_json_c", because it tries
an impossible test, i.e. to add 2 "op" fields in the same patch entry,
something which is impossible in a JSON object.

For the 'error' cases, right now we only test that an error happens.
Later, we can extend this to check the error codes.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
2023-07-31 22:18:03 -04:00
Alexandru Ardelean 1c38dea651 json_pointer: move array out-of-bounds check outside of is_valid_index()
The out-of-bounds check is useful when trying to index/obtain a value from
an array.
However, when we set a value to a specific JSON pointer, we can allow
values that are outside the length of the current array.
The RFC6901 doc isn't clear on that aspect, and doing so is a bit more
in-line with how json_object_array_{put,insert}_idx() functions behave.

This changes the behavior of json_pointer_set{f}() because now a value can
be set anywhere in the array.

Also, added a test-case for this behavior change.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
2023-07-31 22:17:30 -04:00
Alexandru Ardelean d5c5b2caec tests: test1: add test cases for json_object_array_insert_idx()
This change adds a few test cases to test the behavior of the new
json_object_array_insert_idx() function, to make sure it behaves according
to specification in doc-string.

This test uses assert() vs the old method of comparing outputs.
This will cause the test to fail because the outputs won't match, since the
assert() will kick in.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
2023-07-31 22:17:30 -04:00
Eric Haszlakiewicz d0f32a5a43 Stop linking a copy of _json_c_strerror() (strerror_override.c) into the tests.
That hasn't been needed since since commit 6068d3f, which changed that code to
 check an env var instead ("_JSON_C_STRERROR_ENABLE").
Fixes issue #812, about dup symbols in static builds with clang.
2023-03-28 23:08:39 +00:00
Federico Francescon 1a2fdc49e7 Fixed test_int_get expected output 2022-11-16 01:33:02 +01:00