Commit Graph

1115 Commits

Author SHA1 Message Date
Rosen Penev
987d3b2c86 fix compilation with clang
Fixes the following warning:

json_pointer.c:230:7: warning: implicit declaration of function
    'vasprintf' is invalid in C99 [-Wimplicit-function-declaration]
            rc = vasprintf(&path_copy, path_fmt, args);
2020-12-17 19:59:37 -08:00
Eric Hawicz
df27756491 Merge pull request #667 from stoeckmann/regression
Fixed test1 regression.
2020-09-11 20:56:51 -04:00
Tobias Stoeckmann
7af593c140 Fixed test1 regression.
SIZEOF_SIZE_T might be only defined in config.h.

Include config.h for these systems to pass tests which are only
supposed to be run on 32 bit systems.

Fixes issue #666.
2020-09-11 21:09:40 +02:00
Eric Hawicz
785a94b7a2 Merge pull request #665 from stoeckmann/tokener
Handle more allocation failures in json_tokener* functions
2020-08-24 09:51:41 -04:00
Eric Hawicz
eb08a92218 Merge pull request #660 from stoeckmann/arraylist
Validate size arguments in arraylist functions.
2020-08-24 09:51:18 -04:00
Tobias Stoeckmann
369e8477d2 Validate size arguments in arraylist functions.
The array_list_new2 function, which is externally reachable through
json_object_new_array_ext, does not check if specified initial size
actually fits into memory on 32 bit architectures.

It also allows negative values, which could lead to an overflow on these
architectures as well. I have added test cases for these situations.

While at it, also protect array_list_shrink against too large
empty_slots argument. No test added because it takes a huge length
value, therefore a lot of items within the array, to overflow the
calculation. In theory this affects 64 bit sytems as well, but since the
arraylist API is not supposed to be used by external applications
according to its header file, the call is protected due to int
limitation of json_object_array_shrink.
2020-08-24 12:13:50 +02:00
Eric Hawicz
b4e72c2655 Merge pull request #664 from stoeckmann/string
Limit strings at INT_MAX length
2020-08-23 16:43:31 -04:00
Eric Hawicz
f941931804 Merge pull request #663 from stoeckmann/strerror
Properly format errnos in _json_c_strerror
2020-08-23 16:38:21 -04:00
Eric Hawicz
1bc7a6b223 Merge pull request #662 from stoeckmann/random
Prevent signed overflow in get_time_seed
2020-08-23 16:34:40 -04:00
Tobias Stoeckmann
df62119b7f Prevent signed overflow in get_time_seed
Casting time(2) return value to int and multiplying the result with
such a constant will definitely lead to a signed overflow by this day.

Since signed overflows are undefined behaviour in C, avoid this.

Casting to unsigned is more than enough since the upper bits of a
64 bit time_t value will be removed with the int conversion anyway.
2020-08-22 13:25:21 +02:00
Tobias Stoeckmann
bcb6d7d347 Handle allocation failure in json_tokener_new_ex
The allocation of printbuf_new might fail. Return NULL to indicate tis
error to the caller. Otherwise later usage of the returned tokener would
lead to null pointer dereference.
2020-08-22 13:18:10 +02:00
Tobias Stoeckmann
e50154f615 Cap string length at INT_MAX.
Several issues occur if a string is longer than INT_MAX:

- The function json_object_get_string_len returns the length of a string
  as int. If the string is longer than INT_MAX, the result would be
  negative.
- That in turn would lead to possible out of boundary access when
  comparing these strings with memcmp and the returned length as done in
  json_object_equal.
- If json_escape_str is called with such strings, out of boundary
  accesses can occur due to internal int handling (also fixed).
- The string cannot be printed out due to printbuffer limits at
  INT_MAX (which is still true after this commit).

Such huge strings can only be inserted through API calls at this point
because input files are capped at INT_MAX anyway.

Due to huge amount of RAM needed to reproduce these issues I have not
added test cases.
2020-08-22 13:16:36 +02:00
Tobias Stoeckmann
583911a66c Aligned comment in _json_object_new_string
The comment only aligns correctly if tab size is 4. Replaced
spaces with tabs to stay in sync with style of other lines.
2020-08-22 13:07:45 +02:00
Tobias Stoeckmann
4298431150 Properly format errnos in _json_c_strerror
The function _json_c_strerror does not properly format unknown errnos.
The int to ascii loop ignores the leading digit if the number can be
divided by 10 and if an errno has been formatted, shorter errnos would
not properly terminate the newly created string, showing the ending
numbers of the previous output.

A test case has been added to show these effects.

Since this function has been introduced for tests, the effect of this on
real life code is basically non-existing. First an environment variable
has to be set to activate this strerror code and second an unknown errno
would have to be encountered.
2020-08-22 11:35:50 +02:00
Eric Haszlakiewicz
2b439ea598 Fix json_object_get_boolean() doc for the object and array cases (always returns 0), and add those cases to the test_cast test.
See also issue #658.
2020-08-17 14:57:21 +00:00
Eric Hawicz
cf30cba4ac Merge pull request #657 from stoeckmann/getrandom
Use GRND_NONBLOCK with getrandom.
2020-08-15 15:01:41 -04:00
Tobias Stoeckmann
f052e42f56 Use GRND_NONBLOCK with getrandom.
The json-c library is used in cryptsetup for LUKS2 header information.
Since cryptsetup can be called very early during boot, the developers
avoid getrandom() calls in their own code base for now. [1]

Introducing a blocking getrandom() call in json-c therefore introduces
this issue for cryptsetup as well. Even though cryptsetup issues do not
have to be json-c issues, here is my proposal:

Let's use a non-blocking call, falling back to other sources if the call
would block. Since getrandom() accesses urandom, it must mean that we
are in an early boot phase -- otherwise the call would not block
according to its manual page.

As stated in manual page of random(4), accessing /dev/urandom won't
block but return weak random numbers, therefore this fallback would work
for json-c.

While at it, fixed the debug message.

[1] https://gitlab.com/cryptsetup/cryptsetup/-/merge_requests/47
    which references to https://lwn.net/Articles/800509/
2020-08-15 15:52:17 +02:00
Eric Hawicz
104b408ee8 Merge pull request #656 from pogaram/fix-warnings
Fixed warnings
2020-08-14 16:57:32 -04:00
Aram Poghosyan
0ffb384409 Fixed warnings 2020-08-14 11:45:33 +04:00
Eric Hawicz
98b7ee93fd Merge pull request #655 from MarcT512/issue654
json_parse: Fix read past end of buffer
2020-08-07 10:18:30 -04:00
Marc
4e9e44e525 Fix read past end of buffer
Resolves https://github.com/json-c/json-c/issues/654
2020-08-07 10:49:45 +01:00
Eric Hawicz
56a89f902f Merge pull request #653 from lamby/966657-json-c-please-make-the-build-reproducible
Make the documentation build reproducibly
2020-08-01 22:06:38 -04:00
Chris Lamb
46eea84554 Make the documentation build reproducibly
Whilst working on the Reproducible Builds effort [0] I noticed that
json-c could not be built reproducibly.

This is because it used the full, absolute path name as an (sanitised)
input to a filename, resulting in some binary package containing, for
example:

  /usr/share/doc/libjson-c-dev/html/md__build_1st_json-c-0_815_issues_closed_for_0_813.html
                                        ^^^^^^^^^^^^^^^^^^^^^^
or

  /usr/share/doc/libjson-c-dev/html/md__build_2_json-c-0_815_2nd_issues_closed_for_0_813.html
                                        ^^^^^^^^^^^^^^^^^^^^^^^^

These differing values are based on the path in which json-c is built. This was
originally filed in Debian as #966657 [1].

 [0] https://reproducible-builds.org/
 [1] https://bugs.debian.org/966657
2020-08-01 11:26:55 +01:00
Eric Hawicz
88cce7b9c5 Merge pull request #651 from alanc/getrandom
Getrandom
2020-07-31 20:30:11 -04:00
Alan Coopersmith
6cf4847796 Use getrandom() if available in json_c_get_random_seed
Lower overhead than opening & reading from /dev/urandom, and works
in chroots and other situtations where /dev/urandom is not available.
Falls back to existing methods when kernel doesn't support the syscall.
2020-07-31 08:28:07 -07:00
Eric Haszlakiewicz
002411293d Issue #649: Drop the generated doc/Doxyfile when creating a release. 2020-07-28 03:52:22 +00:00
Eric Hawicz
66f8ca3c03 Merge pull request #650 from sartura/readme-update
README: fix spelling errors
2020-07-27 10:31:05 -04:00
Jakov Smolic
55bf2d365d README: fix spelling errors
Signed-off-by: Jakov Smolic <jakov.smolic@sartura.hr>
2020-07-27 15:05:55 +02:00
Eric Haszlakiewicz
47189b5ff1 Include updating the json-c-current-releaes gh-pages symlink as part of the release process. 2020-07-26 15:51:07 +00:00
Eric Haszlakiewicz
de02d09c32 Update the master branch to version 0.15.99 2020-07-26 15:26:53 +00:00
Eric Haszlakiewicz
870965e1ea Update AUTHORS, add issues_closed_for_0.15.md, tweak the release checklist slightly. 2020-07-24 03:17:13 +00:00
Eric Hawicz
616b1050b2 Merge pull request #648 from MarcT512/rbf
Fix "may be used uninitialized" Release build failure
2020-07-23 22:26:58 -04:00
Marc
4a23d3413d Fix "may be used uninitialized" Release build failure
Fixes https://github.com/json-c/json-c/issues/647
2020-07-23 18:19:12 +01:00
Eric Haszlakiewicz
730e3d044f Issue #594 - provide an OVERRIDE_GET_RANDOM_SEED cmake variable to override json_c_get_random_seed() for embedded platforms where time(NULL) doesn't work.
Example:
mkdir build && cd build
cmake -DOVERRIDE_GET_RANDOM_SEED='do { extern uint32_t getMsTicks(void); int ms = getMsTicks() * 433494437; return ms; } while(0)' ..
2020-07-22 02:25:03 +00:00
Eric Hawicz
64de4b6e9f Merge pull request #646 from pascal-cuoq/fix_645
Cast to unsigned char instead of int when calling tolower (Fixes #645)
2020-07-21 21:24:59 -04:00
Pascal Cuoq
1962ba7de3 Fixes #645 2020-07-21 17:54:26 +02:00
Eric Haszlakiewicz
024e835f4c Update the ChangeLog with recent changes, in preparation for a 0.15 release. 2020-07-20 03:39:01 +00:00
Eric Haszlakiewicz
78a0f2ea5d Remove the obsolete config.h.win32 2020-07-17 03:47:28 +00:00
Eric Haszlakiewicz
e46b9cdb7d Fix a number of things with the generated docs, including translating triple-backtick code blocks into a form doxygen understands. 2020-07-17 03:46:21 +00:00
Eric Haszlakiewicz
9a7de35b92 Add some more detail about how to use json-c in README.md. 2020-07-17 03:42:38 +00:00
Eric Haszlakiewicz
cb10a13e94 Remove the THIS_FUNCTION_IS_DEPRECATED define, we stopped using it long ago. 2020-07-17 03:20:29 +00:00
Eric Haszlakiewicz
2508109b18 Remove the obsolete README.json_object-split.md, and mark README.md as being the doxygen mainpage. 2020-07-12 19:16:19 +00:00
Eric Haszlakiewicz
4d9f6dd22e Issue #642: improve the docs for json_object_put() and json_object_get(). 2020-07-12 18:43:27 +00:00
Eric Haszlakiewicz
2330c6f0de Expand the doc for json_object_array_get_idx() to explain that it does not adjust refcounts. 2020-07-12 17:55:46 +00:00
Eric Haszlakiewicz
6542d33cd1 Issue #641: Add a cast to void * to address some theoretically undefined printf behavior. 2020-07-11 15:03:00 +00:00
Eric Haszlakiewicz
10a9ac245e Issue #642: improve docs for json_tokener.h and json_object_object_add(). 2020-07-11 04:04:58 +00:00
Eric Haszlakiewicz
6fa8b7ff42 Don't export json-c symbols starting with an underscore, put deprecated exports into a "JSONC_PRIVATE" version, and note stuff to do during releases.
See also PR #639 and issue #621
2020-07-04 19:00:10 +00:00
Eric Haszlakiewicz
6068d3f6d1 Change the strerror_override handling to check $_JSON_C_STRERROR_OVERRIDE instead of using a variable, so we don't need to export it. 2020-07-04 18:58:00 +00:00
Eric Hawicz
b01d50b8dc Merge pull request #639 from smcv/symbol-versions
build: Add a symbol version to all exported symbols
2020-07-04 14:26:20 -04:00
Simon McVittie
c2c94024f5 build: Add symbol versions to all exported symbols
With this version script, newly-linked binaries that depend on the
json-c shared library will refer to its symbols in a versioned form,
preventing their references from being resolved to a symbol of the same
name exported by json-glib or libjansson if those libraries appear in
dependency search order before json-c, which will usually result in
a crash. This is necessary because ELF symbol resolution normally uses
a single flat namespace, not a tree like Windows symbol resolution.
At least one symbol (json_object_iter_next()) is exported by all three
JSON libraries.

Linking with -Bsymbolic is not enough to have this effect in all cases,
because -Bsymbolic only affects symbol lookup within a shared object,
for example when json_object_set_serializer() calls
json_object_set_userdata(). It does not affect calls from external
code into json-c, unless json-c was statically linked into the
external caller.

This change will also not prevent code that depends on json-glib or
libjansson from finding json-c's symbols and crashing; to prevent
that, a corresponding change in json-glib or libjansson would be needed.

Adding a symbol-version is a backwards-compatible change, but once
added, removing or changing the symbol-version on a symbol would be an
incompatible change that requires a SONAME bump.

Resolves: https://github.com/json-c/json-c/issues/621
(when combined with an equivalent change to libjansson).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-07-01 18:24:26 +01:00