38 Commits

Author SHA1 Message Date
Eric Hawicz
6bfab90c87 Issue #867: disallow control characters in strict mode. 2024-09-15 10:37:45 -04:00
Eric Hawicz
ecb7a4c9a3 Merge pull request #864 from pavelzw/patch-1
Build pkg-config for msvc as well
2024-08-29 21:08:52 -04:00
Pavel Zwerschke
906d1581de Update CMakeLists.txt 2024-08-29 10:55:02 +02:00
Pavel Zwerschke
9b8d170d1f Build pkg-config for msvc as well 2024-06-18 00:11:13 +02:00
Eric Hawicz
6e481aa061 Merge pull request #861 from bhaible/handle-another-oom-condition
Handle yet another out-of-memory condition.
2024-05-05 09:49:26 -04:00
Eric Haszlakiewicz
781675758f Although CMAKE_C_COMPILER_FRONTEND_VARIANT is defined, it's not always set to some value. Fix builds for cases when it's blank. 2024-04-28 17:15:42 +00:00
Bruno Haible
833233faa8 Handle yet another out-of-memory condition.
duplocale() can return NULL, with errno set to ENOMEM.
In this case, bail out and set the current error code to
json_tokener_error_memory.
2024-04-22 01:54:10 +02:00
Eric Hawicz
31a22fb2da Issue #857: fix a few places where json_tokener should have been returning json_tokener_error_memory but wasn't. 2024-04-21 10:37:16 -04:00
Eric Hawicz
0051f2dbe0 Merge pull request #858 from alurm/master
json_tokener.h: json_tokener_parse_verbose: fix typo
2024-04-16 11:23:09 -04:00
Alan Urmancheev
0741ce3918 json_tokener.h: json_tokener_parse_verbose: fix typo 2024-04-16 14:56:00 +00:00
Eric Hawicz
e3464a2ab4 Issue #829: attempt to detect clang-cl.exe and pass MSVC-compatile command line arguments. 2024-03-29 22:40:45 -04:00
Eric Hawicz
61016412fb Issue #850: fill in & adjust the "@returns" docs for several functions. 2024-03-29 18:46:05 -04:00
Eric Hawicz
f2eac07129 doxygen can't handle html on heading, split that to separate lines
https://github.com/doxygen/doxygen/issues/10466
2024-03-29 18:45:22 -04:00
Eric Hawicz
e93ae70417 Fix issue #854: Set error=json_tokener_error_memory in json_tokener_parser_verbose() when allocating the tokener fails. 2024-03-29 18:09:12 -04:00
Eric Hawicz
0bc2dd5e60 Merge pull request #852 from fedefrancescon/docs/micro-typo-fix
docs: micro typo in json_object_put doc
2024-03-02 17:31:24 -05:00
Federico Francescon
9c44c7ed52 docs: micro typo in json_object_get doc 2024-03-02 22:41:10 +01:00
Eric Hawicz
401249cbdf Merge pull request #831 from neheb/1
rename WIN32 to _WIN32
2024-02-08 08:11:57 -05: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
Eric Hawicz
dabed80523 Merge pull request #849 from rouault/random_seed_toctou
random_seed.c: add a Coverity Scan suppression
2024-01-08 12:45:39 -05:00
Even Rouault
f6c8eba84e random_seed.c: add a Coverity Scan suppression
Coverity Scan warns about the use of open() after stat() being a
potential TOCTOU (Time of check time of use) issue. But here there is no
such issue.
2024-01-07 20:55:38 +01:00
Eric Hawicz
76f819e51d Merge pull request #846 from evo-i/CMP0153
Use execute_process instead of exec_program
2023-12-17 07:23:07 -05:00
evo
eef983b1df Update CMakeLists.txt
Replace with `execute_process` available on v3.0+
2023-12-17 11:19:20 +03:00
evo
c0cf4bc23b Update CMakeLists.txt
Now saved to variable.
2023-12-17 00:32:21 +03:00
evo
e85c8ada54 Fix ECHO_OUTPUT_VARIABLE 2023-12-17 00:23:51 +03:00
evo
2c84476c77 [CMP0153](https://cmake.org/cmake/help/latest/policy/CMP0153.html) 2023-12-12 16:28:41 +03:00
Eric Haszlakiewicz
407ddb4350 Issue #842 - fix one particular sign conversion warning.
There are many others that show up if we were to add -Wsign-conversions,
but this is the only one using a literal constant.
2023-11-30 13:59:13 +00:00
Eric Hawicz
33337523f5 Merge pull request #839 from ffontaine/master
json_pointer.c: initialize idx
2023-11-08 18:11:13 -05:00
Fabrice Fontaine
7ff7eab603 json_pointer.c: initialize idx
Fix the following build failure with gcc 5:

/home/thomas/autobuild/instance-2/output-1/build/json-c-0.17/json_pointer.c: In function 'json_pointer_result_get_recursive':
/home/thomas/autobuild/instance-2/output-1/build/json-c-0.17/json_pointer.c:193:25: error: 'idx' may be used uninitialized in this function [-Werror=maybe-uninitialized]
    res->index_in_parent = idx;
                         ^

Fixes:
 - http://autobuild.buildroot.org/results/523b35a979d59121fe4e18c38171792b06233940/

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2023-11-08 22:42:48 +01:00
Eric Hawicz
88bce2b38e Merge pull request #837 from HansolChoe/fix-tokener-parse-ex-fuzzer
Add type checking for parsed objects in tokener_parse_ex_fuzzer
2023-10-19 07:49:32 -04:00
HansolChoe
a907f7dd1b tokener_parse_ex_fuzzer: add type checking for parsed object 2023-10-19 16:55:15 +09:00
Eric Hawicz
ad8b8afa7d Take 2 fixing the placement of json_tokener_error_memory in the enum. (json_tokener_error_size is an actual error, *not* a measure of the size of the enum!) 2023-09-22 22:26:21 -04:00
Eric Hawicz
4186537557 Merge pull request #827 from robert-pang/master
Resolve build issue in tokener_parse_ex_fuzzer.c
2023-09-11 00:13:45 +02:00
Eric Hawicz
9ff6b68baf Merge pull request #826 from emlix/cmake-policies
CMake: remove needless policy setting
2023-09-11 00:10:55 +02:00
Robert Pang
1a7defaa69 Fix variable and API names in tokener_parse_ex_fuzzer.cc to resolve build issue. 2023-09-05 13:58:51 -07:00
Rolf Eike Beer
c4a615a052 CMake: request all policies up to CMake 3.12 being set to NEW 2023-09-05 14:31:24 +02:00
Rolf Eike Beer
159822dd8a CMake: request consistent minimum version 2023-09-05 14:31:14 +02:00
Rolf Eike Beer
990acb4e19 CMake: remove needless policy setting
These policies were all introduced before CMake 3.9, so they will automatically
be initialized to the new behavior when requesting a minimum version of 3.9.
2023-09-05 12:14:46 +02:00
Eric Haszlakiewicz
502522a93d Update the master branch to version 0.17.99 2023-08-12 19:08:59 +00:00
17 changed files with 153 additions and 81 deletions

View File

@@ -3,24 +3,11 @@
# and many OpenWRT packages require, much newer CMake packages.
# We're stopping before 3.10 because that version starts requiring
# c++11, which isn't available on e.g HPUX.
cmake_minimum_required(VERSION 3.9)
# The project() command manages VERSION variables.
cmake_policy(SET CMP0048 NEW)
cmake_minimum_required(VERSION 3.9...3.12)
# JSON-C library is C only project.
# PROJECT_VERSION{,_MAJOR,_MINOR,_PATCH} set by project():
project(json-c LANGUAGES C VERSION 0.16.99)
# Targets may not link directly to themselves.
cmake_policy(SET CMP0038 NEW)
# MACOSX_RPATH is enabled by default.
# We set it explicitly to avoid the warning
cmake_policy(SET CMP0042 NEW)
# Only interpret if() arguments as variables or keywords when unquoted.
cmake_policy(SET CMP0054 NEW)
project(json-c LANGUAGES C VERSION 0.17.99)
# set default build type if not specified by user
if(NOT CMAKE_BUILD_TYPE)
@@ -29,13 +16,6 @@ endif()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
# Include file check macros honor CMAKE_REQUIRED_LIBRARIES
# i.e. the check_include_file() calls will include -lm when checking.
# New in version 3.12.
if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()
include(CTest)
# Set some packaging variables.
@@ -197,9 +177,10 @@ endif()
# uClibc *intentionally* crashes in duplocale(), at least as of:
# https://github.com/ffainelli/uClibc/blob/266bdc1/libc/misc/locale/locale.c#L1322
# So, if it looks like we're compiling for a system like that just disable
# So, if it looks like we're compiling for a system like that just disable
# locale handling entirely.
exec_program(${CMAKE_C_COMPILER} ARGS -dumpmachine OUTPUT_VARIABLE CMAKE_GNU_C_MACHINE)
execute_process (COMMAND ${CMAKE_C_COMPILER} -dumpmachine ERROR_QUIET OUTPUT_VARIABLE CMAKE_GNU_C_MACHINE)
if (CMAKE_GNU_C_MACHINE MATCHES "uclibc")
message(STATUS "Detected uClibc compiler, disabling locale handling")
set(HAVE_SETLOCALE 0)
@@ -295,7 +276,24 @@ message(STATUS "Wrote ${PROJECT_BINARY_DIR}/config.h")
configure_file(${PROJECT_SOURCE_DIR}/cmake/json_config.h.in ${PROJECT_BINARY_DIR}/json_config.h)
message(STATUS "Wrote ${PROJECT_BINARY_DIR}/json_config.h")
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
if (NOT DEFINED CMAKE_C_COMPILER_FRONTEND_VARIANT OR "${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "") # only available in cmake 3.14+
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "MSVC")
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "GNU")
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
# Detect clang-cl.exe, it is Clang but with MSVC compatible command line arguments
execute_process (COMMAND ${CMAKE_C_COMPILER} -? ERROR_QUIET OUTPUT_QUIET RESULT_VARIABLE _clang_result)
if (_clang_result EQUAL 0)
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "MSVC")
else()
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "GNU")
message(STATUS, "clang result is NOT 0")
endif()
endif()
endif()
if ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections")
if ("${DISABLE_WERROR}" STREQUAL "OFF")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
@@ -312,11 +310,11 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL
add_definitions(-D_GNU_SOURCE)
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
if ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "Clang")
# Remove this for 1.0 when we can bump the ABI and actually fix these warnings.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-shorten-64-to-32")
endif()
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
elseif ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DEBUG")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996")
@@ -327,7 +325,7 @@ elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4701")
endif()
if (NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"))
if (NOT ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC"))
check_c_source_compiles(
"
/* uClibc toolchains without threading barf when _REENTRANT is defined */
@@ -472,7 +470,7 @@ add_library(${PROJECT_NAME}
${JSON_C_HEADERS}
)
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION 5.2.0
VERSION 5.3.0
SOVERSION 5)
list(APPEND CMAKE_TARGETS ${PROJECT_NAME})
# If json-c is used as subroject it set to target correct interface -I flags and allow
@@ -545,7 +543,6 @@ install(
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
if (UNIX OR MINGW OR CYGWIN)
SET(prefix ${CMAKE_INSTALL_PREFIX})
# exec_prefix is prefix by default and CMake does not have the
# concept.
@@ -573,7 +570,6 @@ if (UNIX OR MINGW OR CYGWIN)
configure_file(json-c.pc.in json-c.pc @ONLY)
set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
install(FILES ${PROJECT_BINARY_DIR}/json-c.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}")
endif ()
install(FILES ${JSON_C_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/json-c)
@@ -589,4 +585,3 @@ if (NOT MSVC) # cmd line apps don't built on Windows currently.
add_subdirectory(apps)
endif()
endif()

View File

@@ -1,6 +1,6 @@
\mainpage
`json-c`
json-c
========
1. [Overview and Build Status](#overview)
@@ -15,7 +15,8 @@
7. [Linking to libjson-c](#linking)
8. [Using json-c](#using)
JSON-C - A JSON implementation in C <a name="overview"></a>
<a name="overview"></a>
JSON-C - A JSON implementation in C
-----------------------------------
JSON-C implements a reference counting object model that allows you to easily
@@ -29,7 +30,8 @@ if you already have json-c installed and ready to use.
Home page for json-c: https://github.com/json-c/json-c/wiki
Getting Help <a name="gettinghelp"></a>
<a name="gettinghelp"></a>
Getting Help
------------
If you have questions about using json-c, please start a thread on
@@ -47,7 +49,8 @@ features or large changes of any kind, please first start a discussion
on the [forums](https://groups.google.com/forum/#!forum/json-c).
Building on Unix with `git`, `gcc` and `cmake` <a name="buildunix"></a>
<a name="buildunix"></a>
Building on Unix with `git`, `gcc` and `cmake`
--------------------------------------------------
If you already have json-c installed, see [Linking to `libjson-c`](#linking)
@@ -60,7 +63,8 @@ Build Status
Test Status
* [Coveralls](https://coveralls.io/github/json-c/json-c?branch=master) [![Coverage Status](https://coveralls.io/repos/github/json-c/json-c/badge.svg?branch=master)](https://coveralls.io/github/json-c/json-c?branch=master)
### Prerequisites: <a name="installprereq"></a>
<a name="installprereq"></a>
### Prerequisites:
- `gcc`, `clang`, or another C compiler
@@ -80,7 +84,8 @@ sudo apt install doxygen # optional
sudo apt install valgrind # optional
```
### Build instructions: <a name="buildcmds"></a>
<a name="buildcmds"></a>
### Build instructions:
`json-c` GitHub repo: https://github.com/json-c/json-c
@@ -116,7 +121,8 @@ google-chrome doc/html/index.html
```
CMake Options <a name="CMake"></a>
<a name="CMake"></a>
CMake Options
--------------------
The json-c library is built with [CMake](https://cmake.org/cmake-tutorial/),
@@ -188,7 +194,8 @@ cmake-configure can take a few options.
| disable-werror | Avoid treating compiler warnings as fatal errors |
Testing: <a name="testing"></a>
<a name="testing"></a>
Testing:
----------
By default, if valgrind is available running tests uses it.
@@ -224,7 +231,8 @@ JSONC_TEST_TRACE=1 make test
and check the log files again.
Building on Unix and Windows with `vcpkg` <a name="buildvcpkg"></a>
<a name="buildvcpkg"></a>
Building on Unix and Windows with `vcpkg`
--------------------------------------------------
You can download and install JSON-C using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
@@ -237,7 +245,8 @@ You can download and install JSON-C using the [vcpkg](https://github.com/Microso
The JSON-C port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
Building for Android <a name="android">
<a name="android">
Building for Android
----------------------
Building on Android is now particularly well supported, but there
@@ -261,7 +270,8 @@ cmake \
make install
```
Linking to `libjson-c` <a name="linking">
<a name="linking">
Linking to `libjson-c`
----------------------
If your system has `pkgconfig`,
@@ -298,7 +308,8 @@ cd build
cmake -DCMAKE_PREFIX_PATH=/path/to/json_c/install/lib64/cmake ..
```
Using json-c <a name="using">
<a name="using">
Using json-c
------------
To use json-c you can either include json.h, or preferably, one of the

View File

@@ -141,12 +141,10 @@ Use ${release}.99 to indicate a version "newer" than anything on the branch:
Update the version in json_c_version.h
Update the version in CMakeLists.txt
Update RELEASE_CHECKLIST.txt, set release=${release}+1
Update the set_target_properties() line in CmakeLists.txt to match the release branch.
Add a new empty section to the json-c.sym file, for ${release}+1
Update the set_target_properties() line in CmakeLists.txt to match the release branch.
git commit -a -m "Update the master branch to version ${release}.99"
git push

View File

@@ -8,11 +8,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
json_tokener *tok = json_tokener_new();
json_object *obj = json_tokener_parse_ex(tok, data1, size);
json_object_object_foreach(jobj, key, val) {
(void)json_object_get_type(val);
(void)json_object_get_string(val);
if (json_object_is_type(obj, json_type_object)) {
json_object_object_foreach(obj, key, val) {
(void)json_object_get_type(val);
(void)json_object_get_string(val);
}
}
(void)json_object_to_json_string(obj, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED);
(void)json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED);
json_object_put(obj);
json_tokener_free(tok);

View File

@@ -176,3 +176,7 @@ JSONC_0.17 {
json_patch_apply;
# array_list_insert_idx is intentionally not exported
} JSONC_0.16;
JSONC_0.18 {
# global:
} JSONC_0.17;

View File

@@ -17,11 +17,11 @@ extern "C" {
#endif
#define JSON_C_MAJOR_VERSION 0
#define JSON_C_MINOR_VERSION 16
#define JSON_C_MINOR_VERSION 17
#define JSON_C_MICRO_VERSION 99
#define JSON_C_VERSION_NUM \
((JSON_C_MAJOR_VERSION << 16) | (JSON_C_MINOR_VERSION << 8) | JSON_C_MICRO_VERSION)
#define JSON_C_VERSION "0.16.99"
#define JSON_C_VERSION "0.17.99"
#ifndef JSON_EXPORT
#if defined(_MSC_VER) && defined(JSON_C_DLL)

View File

@@ -172,10 +172,10 @@ JSON_EXPORT struct json_object *json_object_get(struct json_object *obj);
* is a member of (unless you know you've called `json_object_get(obj)` to
* explicitly increment the refcount).
*
* NULL may be passed, which which case this is a no-op.
* NULL may be passed, in which case this is a no-op.
*
* @param obj the json_object instance
* @returns 1 if the object was freed.
* @returns 1 if the object was freed, 0 if only the refcount was decremented
* @see json_object_get()
*/
JSON_EXPORT int json_object_put(struct json_object *obj);
@@ -191,6 +191,7 @@ JSON_EXPORT int json_object_put(struct json_object *obj);
json_type_object,
json_type_array,
json_type_string
* @returns 1 if the object is of the specified type, 0 otherwise
*/
JSON_EXPORT int json_object_is_type(const struct json_object *obj, enum json_type type);
@@ -458,9 +459,9 @@ JSON_EXPORT struct json_object *json_object_object_get(const struct json_object
* associated with the given field name.
*
* It is safe to pass a NULL value.
* @returns whether or not the key exists
* @returns 1 if the key exists, 0 otherwise
*/
JSON_EXPORT json_bool json_object_object_get_ex(const struct json_object *obj, const char *key,
JSON_EXPORT int json_object_object_get_ex(const struct json_object *obj, const char *key,
struct json_object **value);
/** Delete the given json_object field
@@ -560,7 +561,7 @@ JSON_EXPORT struct array_list *json_object_get_array(const struct json_object *o
/** Get the length of a json_object of type json_type_array
* @param obj the json_object instance
* @returns an int
* @returns the length of the array
*/
JSON_EXPORT size_t json_object_array_length(const struct json_object *obj);
@@ -1042,7 +1043,7 @@ JSON_EXPORT struct json_object *json_object_new_null(void);
*
* @param obj1 the first json_object instance
* @param obj2 the second json_object instance
* @returns whether both objects are equal or not
* @returns 1 if both objects are equal, 0 otherwise
*/
JSON_EXPORT int json_object_equal(struct json_object *obj1, struct json_object *obj2);

View File

@@ -158,7 +158,7 @@ static int json_pointer_result_get_recursive(struct json_object *obj, char *path
struct json_pointer_get_result *res)
{
struct json_object *parent_obj = obj;
size_t idx;
size_t idx = 0;
char *endp;
int rc;
@@ -231,7 +231,7 @@ int json_pointer_get_internal(struct json_object *obj, const char *path,
res->parent = NULL;
res->obj = obj;
res->key_in_parent = NULL;
res->index_in_parent = -1;
res->index_in_parent = UINT32_MAX;
return 0;
}

View File

@@ -226,7 +226,10 @@ struct json_object *json_tokener_parse_verbose(const char *str, enum json_tokene
tok = json_tokener_new();
if (!tok)
{
*error = json_tokener_error_memory;
return NULL;
}
obj = json_tokener_parse_ex(tok, str, -1);
*error = tok->err;
if (tok->err != json_tokener_success
@@ -338,9 +341,15 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
#ifdef HAVE_USELOCALE
{
locale_t duploc = duplocale(oldlocale);
if (duploc == NULL && errno == ENOMEM)
{
tok->err = json_tokener_error_memory;
return NULL;
}
newloc = newlocale(LC_NUMERIC_MASK, "C", duploc);
if (newloc == NULL)
{
tok->err = json_tokener_error_memory;
freelocale(duploc);
return NULL;
}
@@ -359,7 +368,10 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
{
oldlocale = strdup(tmplocale);
if (oldlocale == NULL)
{
tok->err = json_tokener_error_memory;
return NULL;
}
}
setlocale(LC_NUMERIC, "C");
}
@@ -666,6 +678,12 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
state = json_tokener_state_string_escape;
break;
}
else if ((tok->flags & JSON_TOKENER_STRICT) && c <= 0x1f)
{
// Disallow control characters in strict mode
tok->err = json_tokener_error_parse_string;
goto out;
}
if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok))
{
printbuf_memappend_checked(tok->pb, case_start,
@@ -1254,7 +1272,11 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
goto redo_char;
case json_tokener_state_object_value_add:
json_object_object_add(current, obj_field_name, obj);
if (json_object_object_add(current, obj_field_name, obj) != 0)
{
tok->err = json_tokener_error_memory;
goto out;
}
free(obj_field_name);
obj_field_name = NULL;
saved_state = json_tokener_state_object_sep;

View File

@@ -40,8 +40,8 @@ enum json_tokener_error
json_tokener_error_parse_string,
json_tokener_error_parse_comment,
json_tokener_error_parse_utf8_string,
json_tokener_error_memory,
json_tokener_error_size
json_tokener_error_size, /* A string longer than INT32_MAX was passed as input */
json_tokener_error_memory /* Failed to allocate memory */
};
/**
@@ -230,7 +230,7 @@ JSON_EXPORT void json_tokener_reset(struct json_tokener *tok);
JSON_EXPORT struct json_object *json_tokener_parse(const char *str);
/**
* Parser a json_object out of the string `str`, but if it fails
* Parse a json_object out of the string `str`, but if it fails
* return the error in `*error`.
* @see json_tokener_parse()
* @see json_tokener_parse_ex()

View File

@@ -37,13 +37,13 @@
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef WIN32
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <io.h>
#include <windows.h>
#endif /* defined(WIN32) */
#endif /* defined(_WIN32) */
#if !defined(HAVE_OPEN) && defined(WIN32)
#if !defined(HAVE_OPEN) && defined(_WIN32)
#define open _open
#endif

View File

@@ -229,6 +229,7 @@ static int get_dev_random_seed(int *seed)
if ((buf.st_mode & S_IFCHR) == 0)
return -1;
/* coverity[toctou] */
int fd = open(dev_random_file, O_RDONLY);
if (fd < 0)
{
@@ -253,7 +254,7 @@ static int get_dev_random_seed(int *seed)
/* get_cryptgenrandom_seed */
#ifdef WIN32
#ifdef _WIN32
#define HAVE_CRYPTGENRANDOM 1

View File

@@ -36,6 +36,6 @@ static int json_c_snprintf(char *str, size_t size, const char *format, ...)
#elif !defined(HAVE_SNPRINTF) /* !HAVE_SNPRINTF */
#error snprintf is required but was not found
#endif /* !HAVE_SNPRINTF && defined(WIN32) */
#endif /* !HAVE_SNPRINTF */
#endif /* __snprintf_compat_h */

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.9)
add_executable(test1Formatted test1.c parse_flags.c parse_flags.h)
target_compile_definitions(test1Formatted PRIVATE TEST_FORMATTED=1)
target_link_libraries(test1Formatted PRIVATE ${PROJECT_NAME})

View File

@@ -535,7 +535,7 @@ struct incremental_step
{"{\"a\":}", -1, 5, json_tokener_error_parse_unexpected, 1, 0},
{"{\"a\":1,\"a\":2}", -1, -1, json_tokener_success, 1, 0},
{"\"a\":1}", -1, 3, json_tokener_success, 1, 0},
{"{\"a\":1", -1, -1, json_tokener_continue, 1, 0},
{"{\"a\":1", -1, -1, json_tokener_continue, 1, 0}, //}
{"[,]", -1, 1, json_tokener_error_parse_unexpected, 1, 0},
{"[,1]", -1, 1, json_tokener_error_parse_unexpected, 1, 0},
@@ -595,6 +595,44 @@ struct incremental_step
{"\x7b\x22\x31\x81\x22\x3a\x31\x7d", -1, 3, json_tokener_error_parse_utf8_string, 1,
JSON_TOKENER_VALIDATE_UTF8},
// Note, current asciiz APIs can't parse \x00, skip it
{ "\"0\x01\x02\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \
"\x10\x11\x12\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\"",
-1, -1, json_tokener_success, 1, 0 },
// Test control chars again, this time in strict mode, which should fail
{ "\"\x01\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x02\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x03\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x04\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x05\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x06\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x07\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x08\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x09\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x0a\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x0b\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x0c\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x0d\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x0e\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x0f\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x10\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x11\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x12\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x13\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x14\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x15\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x16\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x17\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x18\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x19\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x1a\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x1b\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x1c\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x1d\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x1e\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{ "\"\x1f\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
{NULL, -1, -1, json_tokener_success, 0, 0},
};

View File

@@ -2,11 +2,11 @@
#undef NDEBUG
#endif
#include "strerror_override.h"
#ifdef WIN32
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <io.h>
#include <windows.h>
#endif /* defined(WIN32) */
#endif /* defined(_WIN32) */
#include <fcntl.h>
#include <limits.h>
#include <stddef.h>

View File

@@ -8,9 +8,9 @@
#include "snprintf_compat.h"
#ifndef WIN32
#ifndef _WIN32
#include <stdarg.h>
#endif /* !defined(WIN32) */
#endif /* !defined(_WIN32) */
#include <stdint.h>
#include <stdlib.h>
@@ -18,10 +18,10 @@
/* CAW: compliant version of vasprintf */
static int vasprintf(char **buf, const char *fmt, va_list ap)
{
#ifndef WIN32
#ifndef _WIN32
static char _T_emptybuffer = '\0';
va_list ap2;
#endif /* !defined(WIN32) */
#endif /* !defined(_WIN32) */
int chars;
char *b;
@@ -30,16 +30,16 @@ static int vasprintf(char **buf, const char *fmt, va_list ap)
return -1;
}
#ifdef WIN32
#ifdef _WIN32
chars = _vscprintf(fmt, ap);
#else /* !defined(WIN32) */
#else /* !defined(_WIN32) */
/* CAW: RAWR! We have to hope to god here that vsnprintf doesn't overwrite
* our buffer like on some 64bit sun systems... but hey, it's time to move on
*/
va_copy(ap2, ap);
chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap2);
va_end(ap2);
#endif /* defined(WIN32) */
#endif /* defined(_WIN32) */
if (chars < 0 || (size_t)chars + 1 > SIZE_MAX / sizeof(char))
{
return -1;