]> granicus.if.org Git - json-c/log
json-c
14 months agoBump up the minimum cmake version to 3.9. master
Eric Haszlakiewicz [Thu, 23 Feb 2023 01:01:14 +0000 (01:01 +0000)]
Bump up the minimum cmake version to 3.9.
This gets us up to a version that supports features we're already using
(i.e. add_compile_options), but stops short of a cmake that requires
c++11, which some OSes still don't support.
Closes issue #774

16 months agoIssue #570: note brief instructions for building on Android.
Eric Haszlakiewicz [Thu, 5 Jan 2023 00:25:09 +0000 (00:25 +0000)]
Issue #570: note brief instructions for building on Android.

16 months agoMerge pull request #804 from yrashk/cmp-0042
Eric Hawicz [Tue, 27 Dec 2022 14:32:33 +0000 (09:32 -0500)]
Merge pull request #804 from yrashk/cmp-0042

Problem: cmake 3.25.1 warns about CMP0042 not being set

16 months agoMerge pull request #803 from yrashk/patch-2
Eric Hawicz [Tue, 27 Dec 2022 14:26:30 +0000 (09:26 -0500)]
Merge pull request #803 from yrashk/patch-2

Problem: confusing error message in snprintf_compat.h

16 months agoMerge pull request #802 from yrashk/patch-1
Eric Hawicz [Tue, 27 Dec 2022 14:25:58 +0000 (09:25 -0500)]
Merge pull request #802 from yrashk/patch-1

Problem: modern CMake warns about version 2.8

16 months agoProblem: cmake 3.25.1 warns about CMP0042 not being set
Yurii Rashkovskii [Fri, 23 Dec 2022 22:59:59 +0000 (14:59 -0800)]
Problem: cmake 3.25.1 warns about CMP0042 not being set

Solution: set it explictly to OLD behavior

16 months agoProblem: confusing error message in snprintf_compat.h
Yurii Rashkovskii [Fri, 23 Dec 2022 22:35:36 +0000 (14:35 -0800)]
Problem: confusing error message in snprintf_compat.h

Solution: fix it to reflect what's happening properly

16 months agoProblem: modern CMake warns about version 2.8
Yurii Rashkovskii [Fri, 23 Dec 2022 22:33:31 +0000 (14:33 -0800)]
Problem: modern CMake warns about version 2.8

The warning is as follows:

```
Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.
```

Solution: set it at 2.8.12

17 months agoMerge pull request #796 from fedefrancescon/test-add-int-get
Eric Hawicz [Thu, 17 Nov 2022 03:23:11 +0000 (22:23 -0500)]
Merge pull request #796 from fedefrancescon/test-add-int-get

Added Test for get int functions

17 months agoFixed `test_int_get` expected output
Federico Francescon [Wed, 16 Nov 2022 00:33:02 +0000 (01:33 +0100)]
Fixed `test_int_get` expected output

17 months agoAdded basic tests for `json_object_get_int`, `json_object_get_int64`, `json_object_ge...
Federico Francescon [Tue, 15 Nov 2022 23:49:18 +0000 (00:49 +0100)]
Added basic tests for `json_object_get_int`, `json_object_get_int64`, `json_object_get_uint64`

18 months agoUpdate expected output for test_parse, missed in the previous commit.
Eric Haszlakiewicz [Sun, 30 Oct 2022 19:42:42 +0000 (19:42 +0000)]
Update expected output for test_parse, missed in the previous commit.

18 months agoExplicitly check for integer overflow/underflow when parsing integers with JSON_TOKEN...
Eric Haszlakiewicz [Sun, 30 Oct 2022 19:29:15 +0000 (19:29 +0000)]
Explicitly check for integer overflow/underflow when parsing integers with JSON_TOKENER_STRICT.

18 months agoApply same EINVAL handling to json_parse_uint64() as was done for json_parse_int64...
Eric Haszlakiewicz [Sun, 30 Oct 2022 03:25:32 +0000 (03:25 +0000)]
Apply same EINVAL handling to json_parse_uint64() as was done for json_parse_int64().  Document that overflow/underflow for these functions is not an error, but sets errno=ERANGE.

18 months agoIssue #792 - set errno=EINVAL if parsing the string in json_parse_int64 fails, to...
Eric Haszlakiewicz [Wed, 26 Oct 2022 02:19:38 +0000 (02:19 +0000)]
Issue #792 - set errno=EINVAL if parsing the string in json_parse_int64 fails, to match the docs for json_object_get_int.

19 months agoMerge pull request #790 from Sarcares/patch-1
Eric Hawicz [Wed, 14 Sep 2022 02:15:48 +0000 (22:15 -0400)]
Merge pull request #790 from Sarcares/patch-1

Small update to README file

19 months agoSmall update to README file
Luca Mannella [Mon, 12 Sep 2022 15:29:47 +0000 (17:29 +0200)]
Small update to README file

it could be necessary to execute make install

20 months agoMerge pull request #784 from rouault/get_time_seed_coverity_scan_silence
Eric Hawicz [Tue, 16 Aug 2022 22:10:06 +0000 (18:10 -0400)]
Merge pull request #784 from rouault/get_time_seed_coverity_scan_silence

get_time_seed(): silence warning emitted by Coverity Scan static analyzer

20 months agoget_time_seed(): silence warning emitted by Coverity Scan static analyzer
Even Rouault [Tue, 16 Aug 2022 09:11:55 +0000 (11:11 +0200)]
get_time_seed(): silence warning emitted by Coverity Scan static analyzer

It warns about the return of time() being truncated to 32 bit, which is
not an issue here.
(this warning was emitted because of the https://github.com/OSGeo/gdal
project embedding a copy of libjson-c and running Coverity Scan
analysis)

20 months agoMerge pull request #783 from kraj/master
Eric Hawicz [Sun, 14 Aug 2022 12:19:19 +0000 (08:19 -0400)]
Merge pull request #783 from kraj/master

Fix build with clang-15+

20 months agojson_pointer.c: Move idx_val declaration to top of function
Khem Raj [Sun, 14 Aug 2022 07:46:28 +0000 (00:46 -0700)]
json_pointer.c: Move idx_val declaration to top of function

This helps compiling with MS compiler, error seems to be
due to defining a variable within the body of the function
its allowed in c99 but not in c89. This should fix build with
MSVC 16.0.40219.1 compiler from Visual Studio 14 2015

Signed-off-by: Khem Raj <raj.khem@gmail.com>
20 months agojson_inttypes.h: Define ssize_t on windows platforms
Khem Raj [Sun, 14 Aug 2022 04:45:11 +0000 (21:45 -0700)]
json_inttypes.h: Define ssize_t on windows platforms

Signed-off-by: Khem Raj <raj.khem@gmail.com>
20 months agoFix build with clang-15+
Khem Raj [Sun, 14 Aug 2022 03:37:03 +0000 (20:37 -0700)]
Fix build with clang-15+

Fixes
json_util.c:63:35: error: a function declaration without a prototype is deprecated in all versions of C [-We
rror,-Wstrict-prototypes]
const char *json_util_get_last_err()
                                  ^
                                   void

Signed-off-by: Khem Raj <raj.khem@gmail.com>
20 months agoMerge pull request #782 from DimitriPapadopoulos/codespell
Eric Hawicz [Sat, 13 Aug 2022 13:43:50 +0000 (09:43 -0400)]
Merge pull request #782 from DimitriPapadopoulos/codespell

Fix typos found by codespell

20 months agoFix typos found by codespell
Dimitri Papadopoulos [Sat, 13 Aug 2022 12:47:40 +0000 (15:47 +0300)]
Fix typos found by codespell

Do not fix typos from past commits found in release notes.

21 months agoApply some of the fixes from PR #740, although by using size_t instead of castings.
Eric Haszlakiewicz [Sun, 31 Jul 2022 19:26:12 +0000 (19:26 +0000)]
Apply some of the fixes from PR #740, although by using size_t instead of castings.

21 months agoMerge pull request #757 from c3h2-ctf/big
Eric Hawicz [Sun, 31 Jul 2022 18:27:32 +0000 (14:27 -0400)]
Merge pull request #757 from c3h2-ctf/big

json_object_from_fd_ex: fail if file is too large

21 months agoIssue #705: disable locale handling when building for a uClibc system because its...
Eric Haszlakiewicz [Sat, 30 Jul 2022 20:27:35 +0000 (20:27 +0000)]
Issue #705: disable locale handling when building for a uClibc system because its duplocale() function (intentionally) crashes.

21 months agoWhen serializing with JSON_C_TO_STRING_PRETTY set, keep the opening and closing curly...
Eric Haszlakiewicz [Sat, 30 Jul 2022 19:27:14 +0000 (19:27 +0000)]
When serializing with JSON_C_TO_STRING_PRETTY set, keep the opening and closing curly or square braces on same line for empty objects or arrays.  Issue #778.

21 months agoUpdate Travis links to point at travis-ci.com instead of travis-ci.org
Eric Haszlakiewicz [Tue, 26 Jul 2022 23:47:58 +0000 (23:47 +0000)]
Update Travis links to point at travis-ci.com instead of travis-ci.org

21 months agoEntirely drop mode bits from open(O_RDONLY) to avoid warnings on certain platforms...
Eric Haszlakiewicz [Tue, 26 Jul 2022 23:43:30 +0000 (23:43 +0000)]
Entirely drop mode bits from open(O_RDONLY) to avoid warnings on certain platforms.  Fixes issue #779.

21 months agoTrim a few travis builds, update others to more recent toolchains.
Eric Haszlakiewicz [Sun, 24 Jul 2022 20:37:14 +0000 (20:37 +0000)]
Trim a few travis builds, update others to more recent toolchains.

21 months agoFix the expected output for test_set_serializer.
Eric Haszlakiewicz [Sun, 24 Jul 2022 19:00:27 +0000 (19:00 +0000)]
Fix the expected output for test_set_serializer.

21 months agoAdd test to check for the memory leak mentioned in issue #781
Eric Haszlakiewicz [Sun, 24 Jul 2022 18:59:26 +0000 (18:59 +0000)]
Add test to check for the memory leak mentioned in issue #781

21 months agoMerge pull request #781 from dddaniel/master
Eric Hawicz [Sun, 24 Jul 2022 18:15:42 +0000 (14:15 -0400)]
Merge pull request #781 from dddaniel/master

Fix memory leak with emtpy strings in json_object_set_string

21 months agoFix memory leak with emtpy strings in json_object_set_string
Daniel Danzberger [Sun, 24 Jul 2022 16:46:03 +0000 (18:46 +0200)]
Fix memory leak with emtpy strings in json_object_set_string

When a json string object is updated with a bigger string, a new
malloc'ed buffer is used to store the new string and it's size is made
negative to indicate that an external buffer is in use.

When that same json string object get's updated again with an empty
stirng (size = 0), the new external malloc'ed buffer is still used.
But the fact that the new size value is not negative removes the
indicator that the externally malloc'ed buffer is used.

This becomes a problem when the object get's updated again with any
other string, because a new buffer will be malloced and linked to the
object while to old one won't be free'd.

This causes a memory leak when updating a json string with
json_object_set_stirng() which has previously been updated
with an empty string.

Example:
--
obj = json_object_new_string("data");
json_object_set_string(obj, "more data");
json_object_set_string(obj, "");
json_object_set_string(obj, "other data"); /* leaks */
--

This commit fixes the issue by free'ing the external buffer when an
empty string is set and use the internal one again.

Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
22 months agoFix issue #775 - use a loop instead of list(TRANSFORM ...) to support cmake < 3.12.
Eric Haszlakiewicz [Mon, 27 Jun 2022 02:15:24 +0000 (02:15 +0000)]
Fix issue #775 - use a loop instead of list(TRANSFORM ...) to support cmake < 3.12.

22 months agoMerge pull request #776 from stoeckmann/typo
Eric Hawicz [Wed, 22 Jun 2022 01:39:00 +0000 (21:39 -0400)]
Merge pull request #776 from stoeckmann/typo

Fix typo

22 months agoFix typo
Tobias Stoeckmann [Tue, 21 Jun 2022 12:39:01 +0000 (14:39 +0200)]
Fix typo

22 months agoFix #771/#768 by marking usage() as "noreturn" instead of using "FALLTHRU" in the...
Eric Haszlakiewicz [Mon, 13 Jun 2022 01:02:53 +0000 (01:02 +0000)]
Fix #771/#768 by marking usage() as "noreturn" instead of using "FALLTHRU" in the case statement where it'd called.

23 months agoMerge pull request #769 from An7ar35/issue-768
Eric Hawicz [Sat, 4 Jun 2022 03:14:16 +0000 (23:14 -0400)]
Merge pull request #769 from An7ar35/issue-768

Issue #768

23 months agomissing 'FALLTHRU' added to sort out error messages when using "-Werror=implicit...
An7ar35 [Wed, 1 Jun 2022 10:36:33 +0000 (12:36 +0200)]
missing 'FALLTHRU' added to sort out error messages when using "-Werror=implicit-fallthrough" flag

23 months agoUnset NDEBUG so assert() is enabled in all tests. One more fix there when building...
Eric Haszlakiewicz [Mon, 30 May 2022 15:39:54 +0000 (15:39 +0000)]
Unset NDEBUG so assert() is enabled in all tests.  One more fix there when building with -DCMAKE_BUILD_TYPE=release.

23 months agoSpecify dependent libraries, including -lbsd, in a more consistent way so linking...
Eric Haszlakiewicz [Mon, 30 May 2022 15:30:11 +0000 (15:30 +0000)]
Specify dependent libraries, including -lbsd, in a more consistent way so linking against a static json-c works better.  Related issue #766
Use target_link_libraries, plus fill in Libs.private in json-c.pc so pkg-config --static --libs works appropriately.
Also, only link against libbsd when arc4random is actually found there.

23 months agoInclude the tests and apps directories at the _end_, since order in the
Eric Haszlakiewicz [Mon, 30 May 2022 14:33:16 +0000 (14:33 +0000)]
Include the tests and apps directories at the _end_, since order in the
cmake rules matters, and fix compile warnings now that we're building
those sources with all the regular flags.

23 months agoAdd --disable-static and --disable-dynamic options to the cmake-configure script.
Eric Haszlakiewicz [Mon, 30 May 2022 14:31:08 +0000 (14:31 +0000)]
Add --disable-static and --disable-dynamic options to the cmake-configure script.

2 years agoNote the DSIABLE_JSON_POINTER and DISABLE_EXTRA_LIBS build options on the README
Eric Haszlakiewicz [Thu, 14 Apr 2022 12:57:43 +0000 (12:57 +0000)]
Note the DSIABLE_JSON_POINTER and DISABLE_EXTRA_LIBS build options on the README

2 years agoAdd a "Getting Help" section to the README.
Eric Haszlakiewicz [Thu, 14 Apr 2022 12:55:32 +0000 (12:55 +0000)]
Add a "Getting Help" section to the README.

2 years agoUpdate the master branch to version 16.99
Eric Haszlakiewicz [Thu, 14 Apr 2022 12:29:39 +0000 (12:29 +0000)]
Update the master branch to version 16.99

2 years agoClarify how to set the uploaded release tarballs to be publically readable.
Eric Haszlakiewicz [Thu, 14 Apr 2022 12:17:59 +0000 (12:17 +0000)]
Clarify how to set the uploaded release tarballs to be publically readable.

2 years agoUpdate the ChangeLog with recent changes, in preparation for a 0.16 release.
Eric Haszlakiewicz [Thu, 14 Apr 2022 00:21:13 +0000 (00:21 +0000)]
Update the ChangeLog with recent changes, in preparation for a 0.16 release.
Add a list of issues closed for this release.

2 years agoAdd new authors since the 0.15 release, tweak instructions for how to update that...
Eric Haszlakiewicz [Wed, 13 Apr 2022 23:16:34 +0000 (23:16 +0000)]
Add new authors since the 0.15 release, tweak instructions for how to update that list.

2 years agoMerge pull request #765 from jvoisin/patch-1
Eric Hawicz [Wed, 13 Apr 2022 18:28:51 +0000 (14:28 -0400)]
Merge pull request #765 from jvoisin/patch-1

Improve a bit the coverage of the fuzzer

2 years agoImprove a bit the coverage of the fuzzer
Julien Voisin [Wed, 13 Apr 2022 13:42:46 +0000 (15:42 +0200)]
Improve a bit the coverage of the fuzzer

2 years agoFix issue #764: adjust test_util_file to match new output (changed in 6e53347)
Eric Haszlakiewicz [Fri, 8 Apr 2022 22:58:24 +0000 (22:58 +0000)]
Fix issue #764: adjust test_util_file to match new output (changed in 6e53347)

2 years agoMerge pull request #758 from c3h2-ctf/context
Eric Hawicz [Mon, 4 Apr 2022 22:01:39 +0000 (18:01 -0400)]
Merge pull request #758 from c3h2-ctf/context

Preserve context if out of memory

2 years agoUpdate issue templates
Eric Hawicz [Mon, 4 Apr 2022 21:10:31 +0000 (17:10 -0400)]
Update issue templates

2 years agoPreserve context if out of memory
Tobias Stoeckmann [Sun, 20 Mar 2022 12:22:46 +0000 (13:22 +0100)]
Preserve context if out of memory

If memory allocation fails in json_c_set_serialization_double_format or
json_object_copy_serializer_data then return with an error value and
preserve previous values without overriding them with NULL.

2 years agoRemove single quote from #error line. Fixes issue #761
Eric Haszlakiewicz [Fri, 25 Mar 2022 01:11:52 +0000 (01:11 +0000)]
Remove single quote from #error line.  Fixes issue #761

2 years agoMerge pull request #760 from BonsaiYi/error
Eric Hawicz [Wed, 23 Mar 2022 04:14:36 +0000 (00:14 -0400)]
Merge pull request #760 from BonsaiYi/error

Code style: removed unneeded double-quotes

2 years agoCode style removed unneeded double-quotes
BonsaY [Mon, 21 Mar 2022 20:10:45 +0000 (21:10 +0100)]
Code style removed unneeded double-quotes

this way, it complies with the other #error usages

2 years agojson_object_from_fd_ex: fail if file is too large
Tobias Stoeckmann [Sun, 20 Mar 2022 12:17:37 +0000 (13:17 +0100)]
json_object_from_fd_ex: fail if file is too large

If the input file is too large to fit into a printbuf then return an
error value instead of silently truncating the parsed content.

This introduces errno handling into printbuf to distinguish between an
input file being too large and running out of memory.

2 years agoMerge pull request #755 from c3h2-ctf/error
Eric Hawicz [Sat, 19 Mar 2022 14:05:48 +0000 (10:05 -0400)]
Merge pull request #755 from c3h2-ctf/error

Fix error messages

2 years agoMerge pull request #754 from c3h2-ctf/doc
Eric Hawicz [Sat, 19 Mar 2022 14:04:58 +0000 (10:04 -0400)]
Merge pull request #754 from c3h2-ctf/doc

Minor improvements to documentation

2 years agoFix error messages
Tobias Stoeckmann [Sat, 19 Mar 2022 09:59:43 +0000 (10:59 +0100)]
Fix error messages

Error messages did not reflect actual function names.

2 years agoFix typos in comments
Tobias Stoeckmann [Sat, 19 Mar 2022 09:39:10 +0000 (10:39 +0100)]
Fix typos in comments

Spotted during code reviews.

2 years agoAdjusted URLs
Tobias Stoeckmann [Sat, 19 Mar 2022 09:34:55 +0000 (10:34 +0100)]
Adjusted URLs

Most of these sites support HTTPS (some forward to HTTPS when accessing
the HTTP versions). Use HTTPS directly if supported.

Some URLs led to 404 error pages. Adjusted the links to point to
new locations.

I did not adjust the Microsoft HTML Help Workshop link because it seems
that this software is not available anymore. Instead of removing the
link entirely I kept it there in case it helps someone to find the
software on archived websites.

2 years agoMerge pull request #748 from c3h2-ctf/printbuf
Eric Hawicz [Mon, 7 Mar 2022 05:06:57 +0000 (00:06 -0500)]
Merge pull request #748 from c3h2-ctf/printbuf

sprintbuf(): test for all vsnprintf error values

2 years agoMerge pull request #752 from c3h2-ctf/typos
Eric Hawicz [Mon, 7 Mar 2022 04:33:42 +0000 (23:33 -0500)]
Merge pull request #752 from c3h2-ctf/typos

Fix typos

2 years agoFix typos
Tobias Stoeckmann [Sun, 6 Mar 2022 15:07:36 +0000 (16:07 +0100)]
Fix typos

Mostly found with codespell and during code review.

2 years agosprintbuf(): test for all vsnprintf error values
Tobias Stoeckmann [Sun, 27 Feb 2022 20:45:28 +0000 (21:45 +0100)]
sprintbuf(): test for all vsnprintf error values

The POSIX specification states that vsnprintf returns "a negative value"
in case of error, but the code checks explicitly only for -1.

2 years agoMerge pull request #749 from c3h2-ctf/sprintbuf
Eric Hawicz [Fri, 4 Mar 2022 02:32:09 +0000 (21:32 -0500)]
Merge pull request #749 from c3h2-ctf/sprintbuf

sprintbuf(): handle printbuf_memappend errors

2 years agoMerge pull request #750 from c3h2-ctf/clearmem
Eric Hawicz [Fri, 4 Mar 2022 02:29:27 +0000 (21:29 -0500)]
Merge pull request #750 from c3h2-ctf/clearmem

printbuf_memset(): set gaps to zero

2 years agoMerge pull request #751 from c3h2-ctf/arguments
Eric Hawicz [Fri, 4 Mar 2022 02:26:22 +0000 (21:26 -0500)]
Merge pull request #751 from c3h2-ctf/arguments

printbuf: do not allow invalid arguments

2 years agosprintbuf(): handle printbuf_memappend errors
Tobias Stoeckmann [Thu, 3 Mar 2022 20:24:27 +0000 (21:24 +0100)]
sprintbuf(): handle printbuf_memappend errors

If errors occur in printbuf_memappend, then these errors should be
propagated through sprintbuf to indicate the error to the user.

Proof of Concept:
```
 #include <err.h>
 #include <limits.h>
 #include <stdio.h>

 #include "json.h"

 int
 main(void) {
  struct printbuf *pb;
  if ((pb = printbuf_new()) == NULL)
   err(1, "printbuf_new");
  if (printbuf_memset(pb, INT_MAX - 9, 'a', 1) < 0)
   errx(1, "printbuf_memset");
  printf("length: %d\n", printbuf_length(pb));
  printf("sprintbuf: %d\n", sprintbuf(pb, "string too long"));
  printf("length: %d\n", printbuf_length(pb));
  printbuf_free(pb);
  return 0;
 }
```

You can see that sprintbuf does not return an error but length is still
the same, i.e. the string "string too long" has not been appended.

I would like to add this as a unit test but it really depends on the
operating system if printbuf_memset() would fail if not enough memory is
available or not.

2 years agoprintbuf_memset(): set gaps to zero
Tobias Stoeckmann [Thu, 3 Mar 2022 20:18:53 +0000 (21:18 +0100)]
printbuf_memset(): set gaps to zero

It is possible to have a printbuf with "gaps", i.e. areas within the
print buffer which have not been initialized by using printbuf_memset.

Always clear memory in such cases.

Example:
```
struct printbuf *pb = printbuf_new();
printbuf_memset(pb, 10, 'a', 2);
```
In this case pb->buf[0] is '\0' but pb->buf[1] up to pb->buf[9] are
not set. The length would be 12 due to successful printbuf_memset.

2 years agoprintbuf: do not allow invalid arguments
Tobias Stoeckmann [Thu, 3 Mar 2022 20:15:19 +0000 (21:15 +0100)]
printbuf: do not allow invalid arguments

If invalid arguments are passed to printbuf functions return -1 to
protect printbuf internals.

2 years agoMerge pull request #745 from c3h2-ctf/vasprintf
Eric Hawicz [Sun, 27 Feb 2022 13:34:21 +0000 (08:34 -0500)]
Merge pull request #745 from c3h2-ctf/vasprintf

vasprintf(): avoid out of memory accesses

2 years agoMerge pull request #746 from rouault/typo_fixes
Eric Hawicz [Sun, 27 Feb 2022 04:45:15 +0000 (23:45 -0500)]
Merge pull request #746 from rouault/typo_fixes

Fix typos in code comments and ChangeLog

2 years agoFix typos in code comments and ChangeLog
Even Rouault [Thu, 24 Feb 2022 23:14:47 +0000 (00:14 +0100)]
Fix typos in code comments and ChangeLog

2 years agovasprintf(): avoid out of memory accesses
Tobias Stoeckmann [Thu, 24 Feb 2022 20:35:44 +0000 (21:35 +0100)]
vasprintf(): avoid out of memory accesses

Systems without vasprintf fall back to implementation in header file
vasprintf_compat.h. This version could run into heap overflow issues
with very long arguments or formats provoking a lot of output.

The vsnprintf function returns a negative value if more than INT_MAX
characters would be written since its int return type could not
handle this (and %n couldn't handle it either).

Before testing for a possible error value the additional char for
\0 is already added. A -1 error code would not be detected.

Increment only after implicitly casting to an unsigned value to avoid
signed integer overflow if INT_MAX has been returned.

Use va_copy to duplicate the original ap argument for multiple uses
on non-WIN32 systems. At least with glibc the test suite would fail
because the arguments are not reset after leaving the vsnprintf call.

Removed support for apparently very old glibc versions which do not
comply with vsnprintf standard descriptions. It breaks support for
modern ones which are not forced to return -1 in case of error. The
standard specifies merely "a negative value".

How to reproduce:

- Use a system without vasprintf
- Alternatively remove -D_GNU_SOURCE from CMakeLists.txt
- Compile and run:

  #include "json.h"
  int main(void) {
    struct printbuf *pb = printbuf_new();
    sprintbuf(pb, "prefix %2147483647s", "*");
    printbuf_free(pb);
    return 0;
  }

2 years agoMerge pull request #739 from rouault/avoid_unsigned_integer_overflow
Eric Hawicz [Sat, 19 Feb 2022 01:21:18 +0000 (20:21 -0500)]
Merge pull request #739 from rouault/avoid_unsigned_integer_overflow

json_escape_str(): avoid harmless unsigned integer overflow

2 years agoMerge pull request #741 from rouault/json_type_to_name_formatter
Eric Hawicz [Sat, 19 Feb 2022 01:08:31 +0000 (20:08 -0500)]
Merge pull request #741 from rouault/json_type_to_name_formatter

json_type_to_name(): use correct printf() formatter

2 years agoMerge pull request #742 from rouault/json_object_copy_serializer_data_add_assertion
Eric Hawicz [Sat, 19 Feb 2022 01:08:02 +0000 (20:08 -0500)]
Merge pull request #742 from rouault/json_object_copy_serializer_data_add_assertion

json_object_copy_serializer_data(): add assertion

2 years agoMerge pull request #744 from Kizuna-Meraki/close-random
Eric Hawicz [Sat, 19 Feb 2022 01:07:33 +0000 (20:07 -0500)]
Merge pull request #744 from Kizuna-Meraki/close-random

Close file on error path.

2 years agoClose file on error path.
Kizuna-Meraki [Thu, 17 Feb 2022 20:27:01 +0000 (21:27 +0100)]
Close file on error path.

The file was only be closed when there was no error and
was being left open when there was an error. By moving
the close(fd) statement out of the if-clause, the file
can be close regardless if there is an error or not.
After the file is closed, it can be checked for errors.

2 years agojson_type_to_name(): use correct printf() formatter
Even Rouault [Sun, 16 Jan 2022 19:48:27 +0000 (20:48 +0100)]
json_type_to_name(): use correct printf() formatter

Was detected by Coverity Scan when analyzing GDAL's code base which has
a copy of json-c

2 years agojson_object_copy_serializer_data(): add assertion
Even Rouault [Sun, 16 Jan 2022 19:50:56 +0000 (20:50 +0100)]
json_object_copy_serializer_data(): add assertion

This makes Coverity Scan happier since it believes that the initial
check ``if (!src->_userdata && !src->_user_delete)`` could mean that
src->_user_data may be nullptr.

2 years agojson_escape_str(): avoid harmless unsigned integer overflow
Even Rouault [Wed, 12 Jan 2022 22:43:03 +0000 (23:43 +0100)]
json_escape_str(): avoid harmless unsigned integer overflow

Current behaviour is perfectly valid, since wrap-over upon overflow is
well defined behaviour for unsigned types, but it is nevertheless nice to be
able to build with -fsanitize=undefined,unsigned-integer-overflow

There is no significant effect on the generated assembly as can be seen
on the diff of objdump -d output on a optimized build (the compiler
just decided to switch the order of a comparison):

@@ -135,8 +135,8 @@
  1d0: 0f 84 70 ff ff ff     je     146 <json_escape_str+0x146>
  1d6: 4c 3b 24 24           cmp    (%rsp),%r12
  1da: 0f 85 2d ff ff ff     jne    10d <json_escape_str+0x10d>
- 1e0: 49 39 f4              cmp    %rsi,%r12
- 1e3: 0f 87 b7 00 00 00     ja     2a0 <json_escape_str+0x2a0>
+ 1e0: 4c 39 e6              cmp    %r12,%rsi
+ 1e3: 0f 82 b7 00 00 00     jb     2a0 <json_escape_str+0x2a0>
  1e9: 48 8b 44 24 18        mov    0x18(%rsp),%rax
  1ee: 64 48 33 04 25 28 00  xor    %fs:0x28,%rax
  1f5: 00 00

2 years agoMerge pull request #737 from tniessen/patch-1
Eric Hawicz [Wed, 12 Jan 2022 02:25:38 +0000 (21:25 -0500)]
Merge pull request #737 from tniessen/patch-1

Fix typo in README

2 years agoFix typo in README
Tobias Nießen [Sun, 9 Jan 2022 23:12:25 +0000 (00:12 +0100)]
Fix typo in README

2 years agoCause the cmake include dirs to also have ${CMAKE_INSTALL_INCLUDEDIR}/json-c, so...
Eric Haszlakiewicz [Wed, 22 Dec 2021 02:52:37 +0000 (02:52 +0000)]
Cause the cmake include dirs to also have ${CMAKE_INSTALL_INCLUDEDIR}/json-c, so downstream packages that use cmake to link against json-c can choose whether to include headers as just e.g. #include <json_object.h>, if they care to do so.
Update the README to better explain this, and make a few other tweaks.

2 years agoAdd linkhash accessor functions (lh_table_head(), lh_entry_next(), etc...) to pave...
Eric Haszlakiewicz [Tue, 30 Nov 2021 03:27:55 +0000 (03:27 +0000)]
Add linkhash accessor functions (lh_table_head(), lh_entry_next(), etc...) to pave the way for making the lh_table and lh_entry structure opaque in the future.
Update the docs to mark all members of those structures deprecated, and
 suggest what to use instead.

2 years agoDrop the REFCOUNT_DEBUG code, it hasn't been used in ages.
Eric Haszlakiewicz [Tue, 30 Nov 2021 03:08:02 +0000 (03:08 +0000)]
Drop the REFCOUNT_DEBUG code, it hasn't been used in ages.

2 years agoMerge pull request #734 from json-c/newer-appveyor
Eric Hawicz [Mon, 29 Nov 2021 18:40:41 +0000 (13:40 -0500)]
Merge pull request #734 from json-c/newer-appveyor

Newer appveyor config for VS2022 etc...
Update the appveyor config to specify "image" instead of just "os", and build for VS2017, VS2019 and VS2022.

2 years agoPut the most recent image first in appveyor builds. newer-appveyor
Eric Haszlakiewicz [Mon, 29 Nov 2021 18:21:05 +0000 (18:21 +0000)]
Put the most recent image first in appveyor builds.

2 years agoSkip most "Release" builds. s/b_config/CONFIGURATION/ to fix artifact creation.
Eric Haszlakiewicz [Mon, 29 Nov 2021 18:18:48 +0000 (18:18 +0000)]
Skip most "Release" builds.  s/b_config/CONFIGURATION/ to fix artifact creation.

2 years agoThere doesn't seem to be a way to extend the appveyor build matrix for just one image...
Eric Haszlakiewicz [Sat, 27 Nov 2021 02:55:29 +0000 (02:55 +0000)]
There doesn't seem to be a way to extend the appveyor build matrix for just one image, so instead list a whole bunch of excluded builds.

2 years agoUse the newer appveyor images to build for VS2017 and VS2019. Trim the number of...
Eric Haszlakiewicz [Sat, 27 Nov 2021 02:29:26 +0000 (02:29 +0000)]
Use the newer appveyor images to build for VS2017 and VS2019.  Trim the number of builds we do.

2 years agoNote the need to also set CTEST_OUTPUT_ON_FAILURE to get test output
Eric Haszlakiewicz [Fri, 26 Nov 2021 22:49:06 +0000 (22:49 +0000)]
Note the need to also set CTEST_OUTPUT_ON_FAILURE to get test output