Skip to content

Commit 06920a4

Browse files
committed
1 parent 05c9403 commit 06920a4

File tree

11 files changed

+164
-23
lines changed

11 files changed

+164
-23
lines changed

vendor/json-c/ChangeLog

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,63 @@
1-
0.17-master:
1+
0.18-master:
22

3-
The below changelog is incomplete. For this merge in mtasa-blue, we are using revision 6e481aa @ https://github.com/json-c/json-c
3+
The below changelog is incomplete. For this merge in mtasa-blue, we are using revision 7bca694 @ https://github.com/json-c/json-c
44

5+
Deprecated and removed features:
6+
--------------------------------
7+
* [Undocumented]
8+
9+
New features
10+
------------
11+
* [Undocumented]
12+
13+
Significant changes and bug fixes
14+
---------------------------------
15+
* [Undocumented]
16+
* MTA's json-c precision mod has been added on top of this update.
17+
18+
* Files modified by MTA:
19+
json_inttypes.h (Upstream commit revert to fix build; see top header in file for details)
20+
json_object.c (Precision mod)
21+
22+
0.18 (up to commit 6bfab90, 2024-09-15)
23+
========================================
24+
25+
Deprecated and removed features:
26+
--------------------------------
27+
* Clean up pre-3.9 CMake support in CMakeLists.txt
28+
29+
New features
30+
------------
31+
* Build pkg-config for msvc as well
32+
33+
Significant changes and bug fixes
34+
---------------------------------
35+
* Critical fix for binary compatibility with 0.16: Move the
36+
json_tokener_error_memory entry to the end of enum json_tokener_error.
37+
* Issue #829: attempt to detect clang-cl.exe and pass MSVC-compatile command
38+
line arguments.
39+
* PR #831 - rename WIN32 to _WIN32
40+
* PR #839 - Fix gcc 5 "may be used uninitialized" failure in json_pointer.c
41+
* PR #849 - random_seed.c: add a Coverity Scan suppression
42+
* Issue #854: Set error=json_tokener_error_memory in
43+
json_tokener_parser_verbose() when allocating the tokener fails.
44+
* Issue #857: fix a few places where json_tokener should have been returning
45+
json_tokener_error_memory but wasn't.
46+
* Handle yet another out-of-memory condition in json_tokener, duplocate can
47+
return NULL.
48+
* Various fixes in the fuzzers
49+
* A few minor doc fixes
50+
51+
***
552

653
0.17 (up to commit 077661f, 2023-08-08)
754
========================================
855

56+
Known Bugs
57+
----------
58+
* DO NOT USE THE 0.17 RELEASE: json_tokener_error_memory in misplaced in the
59+
json_tokener_error enum, leading to binary compatibility issues.
60+
961
Deprecated and removed features:
1062
--------------------------------
1163
* None

vendor/json-c/json.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extern "C" {
2727
#include "json_object.h"
2828
#include "json_object_iterator.h"
2929
#include "json_pointer.h"
30+
#include "json_patch.h"
3031
#include "json_tokener.h"
3132
#include "json_util.h"
3233
#include "linkhash.h"

vendor/json-c/json_c_version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ extern "C" {
1717
#endif
1818

1919
#define JSON_C_MAJOR_VERSION 0
20-
#define JSON_C_MINOR_VERSION 17
20+
#define JSON_C_MINOR_VERSION 18
2121
#define JSON_C_MICRO_VERSION 99
2222
#define JSON_C_VERSION_NUM \
2323
((JSON_C_MAJOR_VERSION << 16) | (JSON_C_MINOR_VERSION << 8) | JSON_C_MICRO_VERSION)
24-
#define JSON_C_VERSION "0.17.99"
24+
#define JSON_C_VERSION "0.18.99"
2525

2626
#ifndef JSON_EXPORT
2727
#if defined(_MSC_VER) && defined(JSON_C_DLL)

vendor/json-c/json_inttypes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This file is modified by MTA, by reverting json-c commit 1ee1210 (See https://github.com/multitheftauto/mtasa-blue/commit/ee7d32a7abcfaf6dc748485c94f03fec4df64b17) and will continue to deviate from json-c master version.
2+
// Description: "Not relevant for us and causes build error"
3+
14

25
/**
36
* @file
@@ -26,4 +29,4 @@
2629
typedef SSIZE_T ssize_t;
2730
#endif
2831

29-
#endif
32+
#endif

vendor/json-c/json_object.c

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ int32_t json_object_get_int(const struct json_object *jso)
721721
int64_t cint64 = 0;
722722
double cdouble;
723723
enum json_type o_type;
724+
errno = 0;
724725

725726
if (!jso)
726727
return 0;
@@ -756,17 +757,34 @@ int32_t json_object_get_int(const struct json_object *jso)
756757
{
757758
case json_type_int:
758759
/* Make sure we return the correct values for out of range numbers. */
759-
if (cint64 <= INT32_MIN)
760+
if (cint64 < INT32_MIN)
761+
{
762+
errno = ERANGE;
760763
return INT32_MIN;
761-
if (cint64 >= INT32_MAX)
764+
}
765+
if (cint64 > INT32_MAX)
766+
{
767+
errno = ERANGE;
762768
return INT32_MAX;
769+
}
763770
return (int32_t)cint64;
764771
case json_type_double:
765772
cdouble = JC_DOUBLE_C(jso)->c_double;
766-
if (cdouble <= INT32_MIN)
773+
if (cdouble < INT32_MIN)
774+
{
775+
errno = ERANGE;
767776
return INT32_MIN;
768-
if (cdouble >= INT32_MAX)
777+
}
778+
if (cdouble > INT32_MAX)
779+
{
780+
errno = ERANGE;
769781
return INT32_MAX;
782+
}
783+
if (isnan(cdouble))
784+
{
785+
errno = EINVAL;
786+
return INT32_MIN;
787+
}
770788
return (int32_t)cdouble;
771789
case json_type_boolean: return JC_BOOL_C(jso)->c_boolean;
772790
default: return 0;
@@ -801,6 +819,7 @@ struct json_object *json_object_new_uint64(uint64_t i)
801819
int64_t json_object_get_int64(const struct json_object *jso)
802820
{
803821
int64_t cint;
822+
errno = 0;
804823

805824
if (!jso)
806825
return 0;
@@ -813,19 +832,33 @@ int64_t json_object_get_int64(const struct json_object *jso)
813832
{
814833
case json_object_int_type_int64: return jsoint->cint.c_int64;
815834
case json_object_int_type_uint64:
816-
if (jsoint->cint.c_uint64 >= INT64_MAX)
835+
if (jsoint->cint.c_uint64 > INT64_MAX)
836+
{
837+
errno = ERANGE;
817838
return INT64_MAX;
839+
}
818840
return (int64_t)jsoint->cint.c_uint64;
819841
default: json_abort("invalid cint_type");
820842
}
821843
}
822844
case json_type_double:
823845
// INT64_MAX can't be exactly represented as a double
824846
// so cast to tell the compiler it's ok to round up.
825-
if (JC_DOUBLE_C(jso)->c_double >= (double)INT64_MAX)
847+
if (JC_DOUBLE_C(jso)->c_double > (double)INT64_MAX)
848+
{
849+
errno = ERANGE;
826850
return INT64_MAX;
827-
if (JC_DOUBLE_C(jso)->c_double <= INT64_MIN)
851+
}
852+
if (JC_DOUBLE_C(jso)->c_double < (double)INT64_MIN)
853+
{
854+
errno = ERANGE;
855+
return INT64_MIN;
856+
}
857+
if (isnan(JC_DOUBLE_C(jso)->c_double))
858+
{
859+
errno = EINVAL;
828860
return INT64_MIN;
861+
}
829862
return (int64_t)JC_DOUBLE_C(jso)->c_double;
830863
case json_type_boolean: return JC_BOOL_C(jso)->c_boolean;
831864
case json_type_string:
@@ -839,6 +872,7 @@ int64_t json_object_get_int64(const struct json_object *jso)
839872
uint64_t json_object_get_uint64(const struct json_object *jso)
840873
{
841874
uint64_t cuint;
875+
errno = 0;
842876

843877
if (!jso)
844878
return 0;
@@ -851,7 +885,10 @@ uint64_t json_object_get_uint64(const struct json_object *jso)
851885
{
852886
case json_object_int_type_int64:
853887
if (jsoint->cint.c_int64 < 0)
888+
{
889+
errno = ERANGE;
854890
return 0;
891+
}
855892
return (uint64_t)jsoint->cint.c_int64;
856893
case json_object_int_type_uint64: return jsoint->cint.c_uint64;
857894
default: json_abort("invalid cint_type");
@@ -860,10 +897,21 @@ uint64_t json_object_get_uint64(const struct json_object *jso)
860897
case json_type_double:
861898
// UINT64_MAX can't be exactly represented as a double
862899
// so cast to tell the compiler it's ok to round up.
863-
if (JC_DOUBLE_C(jso)->c_double >= (double)UINT64_MAX)
900+
if (JC_DOUBLE_C(jso)->c_double > (double)UINT64_MAX)
901+
{
902+
errno = ERANGE;
864903
return UINT64_MAX;
904+
}
865905
if (JC_DOUBLE_C(jso)->c_double < 0)
906+
{
907+
errno = ERANGE;
908+
return 0;
909+
}
910+
if (isnan(JC_DOUBLE_C(jso)->c_double))
911+
{
912+
errno = EINVAL;
866913
return 0;
914+
}
867915
return (uint64_t)JC_DOUBLE_C(jso)->c_double;
868916
case json_type_boolean: return JC_BOOL_C(jso)->c_boolean;
869917
case json_type_string:
@@ -1037,6 +1085,7 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str
10371085
}
10381086
else
10391087
{
1088+
// MTA has a precision mod in json-c, the below .16g instead of .17g by json-c
10401089
const char *std_format = "%.16g";
10411090
int format_drops_decimals = 0;
10421091
int looks_numeric = 0;

vendor/json-c/json_object.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ JSON_EXPORT struct json_object *json_object_new_boolean(json_bool b);
693693
* The type is coerced to a json_bool if the passed object is not a json_bool.
694694
* integer and double objects will return 0 if there value is zero
695695
* or 1 otherwise. If the passed object is a string it will return
696-
* 1 if it has a non zero length.
696+
* 1 if it has a non zero length.
697697
* If any other object type is passed 0 will be returned, even non-empty
698698
* json_type_array and json_type_object objects.
699699
*
@@ -739,9 +739,12 @@ JSON_EXPORT struct json_object *json_object_new_uint64(uint64_t i);
739739
/** Get the int value of a json_object
740740
*
741741
* The type is coerced to a int if the passed object is not a int.
742-
* double objects will return their integer conversion. Strings will be
743-
* parsed as an integer. If no conversion exists then 0 is returned
744-
* and errno is set to EINVAL. null is equivalent to 0 (no error values set)
742+
* double objects will return their integer conversion except for NaN values
743+
* which return INT32_MIN and the errno is set to EINVAL.
744+
* Strings will be parsed as an integer. If no conversion exists then 0 is
745+
* returned and errno is set to EINVAL. null is equivalent to 0 (no error values
746+
* set).
747+
* Sets errno to ERANGE if the value exceeds the range of int.
745748
*
746749
* Note that integers are stored internally as 64-bit values.
747750
* If the value of too big or too small to fit into 32-bit, INT32_MAX or
@@ -783,8 +786,12 @@ JSON_EXPORT int json_object_int_inc(struct json_object *obj, int64_t val);
783786
/** Get the int value of a json_object
784787
*
785788
* The type is coerced to a int64 if the passed object is not a int64.
786-
* double objects will return their int64 conversion. Strings will be
787-
* parsed as an int64. If no conversion exists then 0 is returned.
789+
* double objects will return their int64 conversion except for NaN values
790+
* which return INT64_MIN and the errno is set to EINVAL.
791+
* Strings will be parsed as an int64. If no conversion exists then 0 is
792+
* returned and errno is set to EINVAL. null is equivalent to 0 (no error values
793+
* set).
794+
* Sets errno to ERANGE if the value exceeds the range of int64.
788795
*
789796
* NOTE: Set errno to 0 directly before a call to this function to determine
790797
* whether or not conversion was successful (it does not clear the value for
@@ -798,8 +805,12 @@ JSON_EXPORT int64_t json_object_get_int64(const struct json_object *obj);
798805
/** Get the uint value of a json_object
799806
*
800807
* The type is coerced to a uint64 if the passed object is not a uint64.
801-
* double objects will return their uint64 conversion. Strings will be
802-
* parsed as an uint64. If no conversion exists then 0 is returned.
808+
* double objects will return their uint64 conversion except for NaN values
809+
* which return 0 and the errno is set to EINVAL.
810+
* Strings will be parsed as an uint64. If no conversion exists then 0 is
811+
* returned and errno is set to EINVAL. null is equivalent to 0 (no error values
812+
* set).
813+
* Sets errno to ERANGE if the value exceeds the range of uint64.
803814
*
804815
* NOTE: Set errno to 0 directly before a call to this function to determine
805816
* whether or not conversion was successful (it does not clear the value for

vendor/json-c/json_tokener.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ struct json_tokener *json_tokener_new_ex(int depth)
154154
{
155155
struct json_tokener *tok;
156156

157+
if (depth < 1)
158+
return NULL;
159+
157160
tok = (struct json_tokener *)calloc(1, sizeof(struct json_tokener));
158161
if (!tok)
159162
return NULL;
@@ -182,6 +185,8 @@ struct json_tokener *json_tokener_new(void)
182185

183186
void json_tokener_free(struct json_tokener *tok)
184187
{
188+
if (!tok)
189+
return;
185190
json_tokener_reset(tok);
186191
if (tok->pb)
187192
printbuf_free(tok->pb);
@@ -340,23 +345,31 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
340345

341346
#ifdef HAVE_USELOCALE
342347
{
348+
#ifdef HAVE_DUPLOCALE
343349
locale_t duploc = duplocale(oldlocale);
344350
if (duploc == NULL && errno == ENOMEM)
345351
{
346352
tok->err = json_tokener_error_memory;
347353
return NULL;
348354
}
349355
newloc = newlocale(LC_NUMERIC_MASK, "C", duploc);
356+
#else
357+
newloc = newlocale(LC_NUMERIC_MASK, "C", oldlocale);
358+
#endif
350359
if (newloc == NULL)
351360
{
352361
tok->err = json_tokener_error_memory;
362+
#ifdef HAVE_DUPLOCALE
353363
freelocale(duploc);
364+
#endif
354365
return NULL;
355366
}
356367
#ifdef NEWLOCALE_NEEDS_FREELOCALE
368+
#ifdef HAVE_DUPLOCALE
357369
// Older versions of FreeBSD (<12.4) don't free the locale
358370
// passed to newlocale(), so do it here
359371
freelocale(duploc);
372+
#endif
360373
#endif
361374
uselocale(newloc);
362375
}
@@ -678,6 +691,12 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
678691
state = json_tokener_state_string_escape;
679692
break;
680693
}
694+
else if ((tok->flags & JSON_TOKENER_STRICT) && (unsigned char)c <= 0x1f)
695+
{
696+
// Disallow control characters in strict mode
697+
tok->err = json_tokener_error_parse_string;
698+
goto out;
699+
}
681700
if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok))
682701
{
683702
printbuf_memappend_checked(tok->pb, case_start,

vendor/json-c/json_tokener.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ JSON_EXPORT struct json_tokener *json_tokener_new(void);
206206

207207
/**
208208
* Allocate a new json_tokener with a custom max nesting depth.
209+
* The depth must be at least 1.
209210
* @see JSON_TOKENER_DEFAULT_DEPTH
210211
*/
211212
JSON_EXPORT struct json_tokener *json_tokener_new_ex(int depth);

vendor/json-c/json_util.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
#endif /* HAVE_UNISTD_H */
3939

4040
#ifdef _WIN32
41+
#ifndef WIN32_LEAN_AND_MEAN
4142
#define WIN32_LEAN_AND_MEAN
43+
#endif
4244
#include <io.h>
4345
#include <windows.h>
4446
#endif /* defined(_WIN32) */

vendor/json-c/linkhash.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#endif
2626

2727
#if defined(_MSC_VER) || defined(__MINGW32__)
28+
#ifndef WIN32_LEAN_AND_MEAN
2829
#define WIN32_LEAN_AND_MEAN
30+
#endif
2931
#include <windows.h> /* Get InterlockedCompareExchange */
3032
#endif
3133

0 commit comments

Comments
 (0)