diff --git a/json-c-0.13.1-fix_incorrect_casts_in_calls_to_ctype_functions.patch b/json-c-0.13.1-fix_incorrect_casts_in_calls_to_ctype_functions.patch new file mode 100644 index 0000000..e88d6e2 --- /dev/null +++ b/json-c-0.13.1-fix_incorrect_casts_in_calls_to_ctype_functions.patch @@ -0,0 +1,61 @@ +From f8c632f579c71012f9aca81543b880a579f634fc Mon Sep 17 00:00:00 2001 +From: Eric Haszlakiewicz +Date: Sun, 25 Mar 2018 18:25:58 -0400 +Subject: [PATCH] Issue #407: fix incorrect casts in calls to ctype functions + (isdigit and isspace) so we don't crash when asserts are enabled on certain + platforms and characters > 128 are parsed. + +--- + json_object.c | 2 +- + json_pointer.c | 4 ++-- + json_tokener.c | 2 +- + 3 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/json_object.c b/json_object.c +index 8287163a1c..8a86bc6ea0 100644 +--- a/json_object.c ++++ b/json_object.c +@@ -838,7 +838,7 @@ static int json_object_double_to_json_string_format(struct json_object* jso, + format_drops_decimals = 1; + + if (size < (int)sizeof(buf) - 2 && +- isdigit((int)buf[0]) && /* Looks like *some* kind of number */ ++ isdigit((unsigned char)buf[0]) && /* Looks like *some* kind of number */ + !p && /* Has no decimal point */ + strchr(buf, 'e') == NULL && /* Not scientific notation */ + format_drops_decimals) +diff --git a/json_pointer.c b/json_pointer.c +index 2b2a9ef507..c7e34f76f3 100644 +--- a/json_pointer.c ++++ b/json_pointer.c +@@ -44,7 +44,7 @@ static int is_valid_index(struct json_object *jo, const char *path, int32_t *idx + /* this code-path optimizes a bit, for when we reference the 0-9 index range in a JSON array + and because leading zeros not allowed */ + if (len == 1) { +- if (isdigit((int)path[0])) { ++ if (isdigit((unsigned char)path[0])) { + *idx = (path[0] - '0'); + goto check_oob; + } +@@ -58,7 +58,7 @@ static int is_valid_index(struct json_object *jo, const char *path, int32_t *idx + } + /* RFC states base-10 decimals */ + for (i = 0; i < len; i++) { +- if (!isdigit((int)path[i])) { ++ if (!isdigit((unsigned char)path[i])) { + errno = EINVAL; + return 0; + } +diff --git a/json_tokener.c b/json_tokener.c +index 449a82da6f..561f7303b2 100644 +--- a/json_tokener.c ++++ b/json_tokener.c +@@ -295,7 +295,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok, + + case json_tokener_state_eatws: + /* Advance until we change state */ +- while (isspace((int)c)) { ++ while (isspace((unsigned char)c)) { + if ((!ADVANCE_CHAR(str, tok)) || (!PEEK_CHAR(c, tok))) + goto out; + } diff --git a/json-c-0.13.1-fix_typos.patch b/json-c-0.13.1-fix_typos.patch new file mode 100644 index 0000000..25301d7 --- /dev/null +++ b/json-c-0.13.1-fix_typos.patch @@ -0,0 +1,163 @@ +From 8bd62177e796386fb6382db101c90b57b6138afe Mon Sep 17 00:00:00 2001 +From: janczer +Date: Tue, 24 Apr 2018 16:00:38 +0200 +Subject: [PATCH] Fixed typos + +--- + STYLE.txt | 2 +- + json_object.h | 18 +++++++++--------- + json_pointer.c | 2 +- + tests/test_compare.c | 12 ++++++------ + tests/test_compare.expected | 6 +++--- + 5 files changed, 20 insertions(+), 20 deletions(-) + +diff --git a/STYLE.txt b/STYLE.txt +index e5acd14820..195883c760 100755 +--- a/STYLE.txt ++++ b/STYLE.txt +@@ -7,7 +7,7 @@ Official json-c style: + Aim for readability, not strict conformance to fixed style rules. + These rules are not comprehensive. Look to existing code for guidelines. + Indentation is tab based, with continuations of long lines starting with tabs then spaces for alignment. +-Try to line up components of continuation lines with corresponding part of the line above (i.e. "indent -lp" effect), but avoid excessive identation tha causes extra line wraps. ++Try to line up components of continuation lines with corresponding part of the line above (i.e. "indent -lp" effect), but avoid excessive indentation tha causes extra line wraps. + e.g. (T=tab, S=space): + TTTTsome_long_func_call(arg1, arg2, + TTTTSSSSSSSSSSSSSSSSSSSarg3, arg4); +diff --git a/json_object.h b/json_object.h +index a3a86c0912..30341bcdb7 100644 +--- a/json_object.h ++++ b/json_object.h +@@ -91,7 +91,7 @@ extern "C" { + /** + * A flag for the json_object_object_add_ex function which + * causes the value to be added without a check if it already exists. +- * Note: it is the responsibilty of the caller to ensure that no ++ * Note: it is the responsibility of the caller to ensure that no + * key is added multiple times. If this is done, results are + * unpredictable. While this option is somewhat dangerous, it + * permits potentially large performance savings in code that +@@ -442,7 +442,7 @@ JSON_EXPORT int json_object_object_add_ex(struct json_object* obj, + * + * This returns NULL if the field is found but its value is null, or if + * the field is not found, or if obj is not a json_type_object. If you +- * need to distinguis between these cases, use json_object_object_get_ex(). ++ * need to distinguish between these cases, use json_object_object_get_ex(). + * + * *No* reference counts will be changed. There is no need to manually adjust + * reference counts through the json_object_put/json_object_get methods unless +@@ -624,7 +624,7 @@ JSON_EXPORT int json_object_array_add(struct json_object *obj, + JSON_EXPORT int json_object_array_put_idx(struct json_object *obj, size_t idx, + struct json_object *val); + +-/** Get the element at specificed index of the array (a json_object of type json_type_array) ++/** Get the element at specified index of the array (a json_object of type json_type_array) + * @param obj the json_object instance + * @param idx the index to get the element at + * @returns the json_object at the specified index (or NULL) +@@ -671,7 +671,7 @@ JSON_EXPORT json_bool json_object_get_boolean(const struct json_object *obj); + * + * The type of obj is checked to be a json_type_boolean and 0 is returned + * if it is not without any further actions. If type of obj is json_type_boolean +- * the obect value is chaned to new_value ++ * the object value is changed to new_value + * + * @param obj the json_object instance + * @param new_value the value to be set +@@ -718,7 +718,7 @@ JSON_EXPORT int32_t json_object_get_int(const struct json_object *obj); + * + * The type of obj is checked to be a json_type_int and 0 is returned + * if it is not without any further actions. If type of obj is json_type_int +- * the obect value is changed to new_value ++ * the object value is changed to new_value + * + * @param obj the json_object instance + * @param new_value the value to be set +@@ -763,7 +763,7 @@ JSON_EXPORT int64_t json_object_get_int64(const struct json_object *obj); + * + * The type of obj is checked to be a json_type_int and 0 is returned + * if it is not without any further actions. If type of obj is json_type_int +- * the obect value is chaned to new_value ++ * the object value is changed to new_value + * + * @param obj the json_object instance + * @param new_value the value to be set +@@ -880,7 +880,7 @@ JSON_EXPORT double json_object_get_double(const struct json_object *obj); + * + * The type of obj is checked to be a json_type_double and 0 is returned + * if it is not without any further actions. If type of obj is json_type_double +- * the obect value is chaned to new_value ++ * the object value is changed to new_value + * + * @param obj the json_object instance + * @param new_value the value to be set +@@ -942,10 +942,10 @@ JSON_EXPORT int json_object_set_string(json_object* obj, const char* new_value); + * + * The type of obj is checked to be a json_type_string and 0 is returned + * if it is not without any further actions. If type of obj is json_type_string +- * the obect value is chaned to new_value ++ * the object value is changed to new_value + * + * @param obj the json_object instance +- * @param new_value the value to be set; Since string legth is given in len this need not be zero terminated ++ * @param new_value the value to be set; Since string length is given in len this need not be zero terminated + * @param len the length of new_value + * @returns 1 if value is set correctly, 0 otherwise + */ +diff --git a/json_pointer.c b/json_pointer.c +index c7e34f76f3..9531c036c8 100644 +--- a/json_pointer.c ++++ b/json_pointer.c +@@ -28,7 +28,7 @@ + static void string_replace_all_occurrences_with_char(char *s, const char *occur, char repl_char) + { + int slen = strlen(s); +- int skip = strlen(occur) - 1; /* length of the occurence, minus the char we're replacing */ ++ int skip = strlen(occur) - 1; /* length of the occurrence, minus the char we're replacing */ + char *p = s; + while ((p = strstr(p, occur))) { + *p = repl_char; +diff --git a/tests/test_compare.c b/tests/test_compare.c +index c7e44f6ea6..cba328cf4b 100644 +--- a/tests/test_compare.c ++++ b/tests/test_compare.c +@@ -18,19 +18,19 @@ int main() + struct json_object *int3 = json_object_new_int(1); + + if (!json_object_equal(int1, int2)) +- printf("JSON integer comparision is correct\n"); ++ printf("JSON integer comparison is correct\n"); + else +- printf("JSON integer comparision failed\n"); ++ printf("JSON integer comparison failed\n"); + + if (json_object_equal(int1, int1)) +- printf("JSON same object comparision is correct\n"); ++ printf("JSON same object comparison is correct\n"); + else +- printf("JSON same object comparision failed\n"); ++ printf("JSON same object comparison failed\n"); + + if (json_object_equal(int2, int3)) +- printf("JSON same integer comparision is correct\n"); ++ printf("JSON same integer comparison is correct\n"); + else +- printf("JSON same integer comparision failed\n"); ++ printf("JSON same integer comparison failed\n"); + + json_object_put(int1); + json_object_put(int2); +diff --git a/tests/test_compare.expected b/tests/test_compare.expected +index 46f03c4101..5468f83d2e 100644 +--- a/tests/test_compare.expected ++++ b/tests/test_compare.expected +@@ -1,6 +1,6 @@ +-JSON integer comparision is correct +-JSON same object comparision is correct +-JSON same integer comparision is correct ++JSON integer comparison is correct ++JSON same object comparison is correct ++JSON same integer comparison is correct + Comparing equal strings is correct + Comparing different strings is correct + Comparing equal doubles is correct diff --git a/json-c-0.13.1-parse_test_UTF8_BOM.patch b/json-c-0.13.1-parse_test_UTF8_BOM.patch new file mode 100644 index 0000000..a8e047d --- /dev/null +++ b/json-c-0.13.1-parse_test_UTF8_BOM.patch @@ -0,0 +1,75 @@ +From da4b34355da023c439e96bc6ca31886cd69d6bdb Mon Sep 17 00:00:00 2001 +From: Eric Haszlakiewicz +Date: Sun, 25 Mar 2018 18:23:42 -0400 +Subject: [PATCH] Add an parse test for content starting with a UTF8 BOM, which + is _not_ a valid start to a JSON message. + +--- + tests/test_parse.c | 16 +++++++++++++++- + tests/test_parse.expected | 5 ++++- + 2 files changed, 19 insertions(+), 2 deletions(-) + +diff --git a/tests/test_parse.c b/tests/test_parse.c +index ee1f8387b3..f46651b0a1 100644 +--- a/tests/test_parse.c ++++ b/tests/test_parse.c +@@ -9,6 +9,7 @@ + #include "json_visit.h" + + static void test_basic_parse(void); ++static void test_utf8_parse(void); + static void test_verbose_parse(void); + static void test_incremental_parse(void); + +@@ -19,6 +20,8 @@ int main(void) + static const char separator[] = "=================================="; + test_basic_parse(); + puts(separator); ++ test_utf8_parse(); ++ puts(separator); + test_verbose_parse(); + puts(separator); + test_incremental_parse(); +@@ -107,6 +110,17 @@ static void test_basic_parse() + single_basic_parse("[18446744073709551616]", 1); + } + ++static void test_utf8_parse() ++{ ++ // json_tokener_parse doesn't support checking for byte order marks. ++ // It's the responsibility of the caller to detect and skip a BOM. ++ // Both of these checks return null. ++ char utf8_bom[] = { 0xEF, 0xBB, 0xBF, 0x00 }; ++ char utf8_bom_and_chars[] = { 0xEF, 0xBB, 0xBF, '{', '}', 0x00 }; ++ single_basic_parse(utf8_bom, 0); ++ single_basic_parse(utf8_bom_and_chars, 0); ++} ++ + // Clear the re-serialization information that the tokener + // saves to ensure that the output reflects the actual + // values we parsed, rather than just the original input. +@@ -145,7 +159,7 @@ static void test_verbose_parse() + /* b/c the string starts with 'f' parsing return a boolean error */ + assert (error == json_tokener_error_parse_boolean); + +- puts("json_tokener_parse_versbose() OK"); ++ puts("json_tokener_parse_verbose() OK"); + } + + struct incremental_step { +diff --git a/tests/test_parse.expected b/tests/test_parse.expected +index ada61411fe..5d3976a745 100644 +--- a/tests/test_parse.expected ++++ b/tests/test_parse.expected +@@ -51,7 +51,10 @@ new_obj.to_string([0e+])=[ 0.0 ] + new_obj.to_string([0e+-1])=null + new_obj.to_string([18446744073709551616])=[ 9223372036854775807 ] + ================================== +-json_tokener_parse_versbose() OK ++new_obj.to_string()=null ++new_obj.to_string({})=null ++================================== ++json_tokener_parse_verbose() OK + ================================== + Starting incremental tests. + Note: quotes and backslashes seen in the output here are literal values passed diff --git a/json-c.spec b/json-c.spec index d8db479..3974d96 100644 --- a/json-c.spec +++ b/json-c.spec @@ -16,7 +16,7 @@ Name: json-c Version: 0.13.1 -Release: 1%{?dist} +Release: 2%{?dist} Summary: JSON implementation in C License: MIT @@ -26,6 +26,11 @@ Source0: %{url}/archive/%{name}-%{version}-%{reldate}.tar.gz Source1: %{url}/archive/%{name}-%{version_old}-%{reldate_old}.tar.gz %endif +# Cherry-picked from upstream. +Patch0: %{url}/commit/da4b34355da023c439e96bc6ca31886cd69d6bdb.patch#/%{name}-0.13.1-parse_test_UTF8_BOM.patch +Patch1: %{url}/commit/f8c632f579c71012f9aca81543b880a579f634fc.patch#/%{name}-0.13.1-fix_incorrect_casts_in_calls_to_ctype_functions.patch +Patch2: %{url}/commit/8bd62177e796386fb6382db101c90b57b6138afe.patch#/%{name}-0.13.1-fix_typos.patch + BuildRequires: libtool %description @@ -170,6 +175,9 @@ end %changelog +* Tue May 08 2018 Björn Esser - 0.13.1-2 +- Add some cherry-picked fixes from upstream master + * Tue Mar 06 2018 Björn Esser - 0.13.1-1 - New upstream release (rhbz#1552053)