Commit Graph

1221 Commits

Author SHA1 Message Date
Eric Haszlakiewicz
f2fc1ca00a Note the DSIABLE_JSON_POINTER and DISABLE_EXTRA_LIBS build options on the README 2022-04-14 12:57:43 +00:00
Eric Haszlakiewicz
acccefd770 Add a "Getting Help" section to the README. 2022-04-14 12:55:32 +00:00
Eric Haszlakiewicz
de5a64888a Update the master branch to version 16.99 2022-04-14 12:29:39 +00:00
Eric Haszlakiewicz
7e3eba72db Clarify how to set the uploaded release tarballs to be publically readable. 2022-04-14 12:17:59 +00:00
Eric Haszlakiewicz
7d303478a4 Update the ChangeLog with recent changes, in preparation for a 0.16 release.
Add a list of issues closed for this release.
2022-04-14 01:05:38 +00:00
Eric Haszlakiewicz
66dcdf549e Add new authors since the 0.15 release, tweak instructions for how to update that list. 2022-04-14 01:04:53 +00:00
Eric Hawicz
4902f9cb87 Merge pull request #765 from jvoisin/patch-1
Improve a bit the coverage of the fuzzer
2022-04-13 14:28:51 -04:00
Julien Voisin
558d48a6f3 Improve a bit the coverage of the fuzzer 2022-04-13 15:42:46 +02:00
Eric Haszlakiewicz
46b58ad9e7 Fix issue #764: adjust test_util_file to match new output (changed in 6e53347) 2022-04-08 22:58:24 +00:00
Eric Hawicz
0b937f6173 Merge pull request #758 from c3h2-ctf/context
Preserve context if out of memory
2022-04-04 18:01:39 -04:00
Eric Hawicz
65274cf3b5 Update issue templates 2022-04-04 17:10:31 -04:00
Tobias Stoeckmann
0c0d901443 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.
2022-03-31 18:05:48 +02:00
Eric Haszlakiewicz
e244146dfd Remove single quote from #error line. Fixes issue #761 2022-03-25 01:12:07 +00:00
Eric Hawicz
a1c092bd7b Merge pull request #760 from BonsaiYi/error
Code style: removed unneeded double-quotes
2022-03-23 00:14:36 -04:00
BonsaY
716978f20d Code style removed unneeded double-quotes
this way, it complies with the other #error usages
2022-03-21 21:10:45 +01:00
Eric Hawicz
79459b2de2 Merge pull request #755 from c3h2-ctf/error
Fix error messages
2022-03-19 10:05:48 -04:00
Eric Hawicz
2326e34390 Merge pull request #754 from c3h2-ctf/doc
Minor improvements to documentation
2022-03-19 10:04:58 -04:00
Tobias Stoeckmann
6e533471a8 Fix error messages
Error messages did not reflect actual function names.
2022-03-19 10:59:43 +01:00
Tobias Stoeckmann
a7d85bfba9 Fix typos in comments
Spotted during code reviews.
2022-03-19 10:39:56 +01:00
Tobias Stoeckmann
cbc603b587 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.
2022-03-19 10:34:55 +01:00
Eric Hawicz
f0d93cee14 Merge pull request #748 from c3h2-ctf/printbuf
sprintbuf(): test for all vsnprintf error values
2022-03-07 00:06:57 -05:00
Eric Hawicz
9b832c8710 Merge pull request #752 from c3h2-ctf/typos
Fix typos
2022-03-06 23:33:42 -05:00
Tobias Stoeckmann
543a8eb5f9 Fix typos
Mostly found with codespell and during code review.
2022-03-06 16:07:36 +01:00
Tobias Stoeckmann
94b2a0cb29 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.
2022-03-06 16:05:32 +01:00
Eric Hawicz
a4389f4f30 Merge pull request #749 from c3h2-ctf/sprintbuf
sprintbuf(): handle printbuf_memappend errors
2022-03-03 21:32:09 -05:00
Eric Hawicz
4493db76d6 Merge pull request #750 from c3h2-ctf/clearmem
printbuf_memset(): set gaps to zero
2022-03-03 21:29:27 -05:00
Eric Hawicz
1491d92038 Merge pull request #751 from c3h2-ctf/arguments
printbuf: do not allow invalid arguments
2022-03-03 21:26:22 -05:00
Tobias Stoeckmann
d07da04c14 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.
2022-03-03 21:24:27 +01:00
Tobias Stoeckmann
63c602ff80 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.
2022-03-03 21:18:53 +01:00
Tobias Stoeckmann
4355242477 printbuf: do not allow invalid arguments
If invalid arguments are passed to printbuf functions return -1 to
protect printbuf internals.
2022-03-03 21:15:19 +01:00
Eric Hawicz
bd56cc8bf7 Merge pull request #745 from c3h2-ctf/vasprintf
vasprintf(): avoid out of memory accesses
2022-02-27 08:34:21 -05:00
Eric Hawicz
723ac8cbb5 Merge pull request #746 from rouault/typo_fixes
Fix typos in code comments and ChangeLog
2022-02-26 23:45:15 -05:00
Even Rouault
3bb54f97e7 Fix typos in code comments and ChangeLog 2022-02-25 00:14:47 +01:00
Tobias Stoeckmann
5c72257220 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;
  }
2022-02-24 23:06:57 +01:00
Eric Hawicz
66cce0a1d7 Merge pull request #739 from rouault/avoid_unsigned_integer_overflow
json_escape_str(): avoid harmless unsigned integer overflow
2022-02-18 20:21:18 -05:00
Eric Hawicz
b11f79c52c Merge pull request #741 from rouault/json_type_to_name_formatter
json_type_to_name(): use correct printf() formatter
2022-02-18 20:08:31 -05:00
Eric Hawicz
78246db72f Merge pull request #742 from rouault/json_object_copy_serializer_data_add_assertion
json_object_copy_serializer_data(): add assertion
2022-02-18 20:08:02 -05:00
Eric Hawicz
a1ea216878 Merge pull request #744 from Kizuna-Meraki/close-random
Close file on error path.
2022-02-18 20:07:33 -05:00
Kizuna-Meraki
d783ad76c7 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.
2022-02-17 21:27:01 +01:00
Even Rouault
f2c0df404b 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
2022-01-31 00:27:41 +01:00
Even Rouault
82d9433813 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.
2022-01-16 20:50:58 +01:00
Even Rouault
296db618e9 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
2022-01-12 23:44:39 +01:00
Eric Hawicz
3b4f1e92ad Merge pull request #737 from tniessen/patch-1
Fix typo in README
2022-01-11 21:25:38 -05:00
Tobias Nießen
928fa96db7 Fix typo in README 2022-01-10 00:12:25 +01:00
Eric Haszlakiewicz
a5c2e11460 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.
2021-12-22 02:52:37 +00:00
Eric Haszlakiewicz
2d2382d709 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.
2021-11-30 03:27:55 +00:00
Eric Haszlakiewicz
320548caf6 Drop the REFCOUNT_DEBUG code, it hasn't been used in ages. 2021-11-30 03:08:02 +00:00
Eric Hawicz
9a90b8477b 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.
2021-11-29 13:40:41 -05:00
Eric Haszlakiewicz
1cb56e705f Put the most recent image first in appveyor builds. 2021-11-29 18:21:05 +00:00
Eric Haszlakiewicz
1763edaba3 Skip most "Release" builds. s/b_config/CONFIGURATION/ to fix artifact creation. 2021-11-29 18:18:48 +00:00