From 9161a3502b936fa3441e9306a5ecdd953a20e126 Mon Sep 17 00:00:00 2001 From: zhangzhangxin Date: Fri, 28 Apr 2023 14:30:04 +0800 Subject: [PATCH 1/3] sync:Add nullptr Json::Value constructor Signed-off-by: zhangzhangxin --- ...c-Add-nullptr-Json-Value-constructor.patch | 121 ++++++++++++++++++ jsoncpp.spec | 6 +- 2 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 0003-sync-Add-nullptr-Json-Value-constructor.patch diff --git a/0003-sync-Add-nullptr-Json-Value-constructor.patch b/0003-sync-Add-nullptr-Json-Value-constructor.patch new file mode 100644 index 0000000..a1a2494 --- /dev/null +++ b/0003-sync-Add-nullptr-Json-Value-constructor.patch @@ -0,0 +1,121 @@ +From 8cd6c2a6db9c35e44d7551d6f2ed3acaf29f1777 Mon Sep 17 00:00:00 2001 +From: zhangzhangxin +Date: Fri, 28 Apr 2023 14:25:44 +0800 +Subject: [PATCH] sync:Add nullptr Json::Value constructor + +Signed-off-by: zhangzhangxin +--- + 0001-sync-Issue-1182-Fix-fuzzing-bug.patch | 40 +++++++++++++++++++ + ...sprint-because-it-is-locale-specific.patch | 40 +++++++++++++++++++ + include/json/value.h | 1 + + 3 files changed, 81 insertions(+) + create mode 100644 0001-sync-Issue-1182-Fix-fuzzing-bug.patch + create mode 100644 0002-sync-avoid-isprint-because-it-is-locale-specific.patch + +diff --git a/0001-sync-Issue-1182-Fix-fuzzing-bug.patch b/0001-sync-Issue-1182-Fix-fuzzing-bug.patch +new file mode 100644 +index 0000000..79374d4 +--- /dev/null ++++ b/0001-sync-Issue-1182-Fix-fuzzing-bug.patch +@@ -0,0 +1,40 @@ ++From 0398d63a8435d5b8f71f07aa8c42e7d65815f97e Mon Sep 17 00:00:00 2001 ++From: zhangzhangxin ++Date: Fri, 28 Apr 2023 10:50:40 +0800 ++Subject: [PATCH] sync:Issue 1182: Fix fuzzing bug ++ ++Signed-off-by: zhangzhangxin ++--- ++ src/lib_json/json_reader.cpp | 7 +++++-- ++ test/data/fail_invalid_quote.json | 1 + ++ 2 files changed, 6 insertions(+), 2 deletions(-) ++ create mode 100644 test/data/fail_invalid_quote.json ++ ++diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp ++index 23cbe60..19922a8 100644 ++--- a/src/lib_json/json_reader.cpp +++++ b/src/lib_json/json_reader.cpp ++@@ -1175,8 +1175,11 @@ bool OurReader::readToken(Token& token) { ++ if (features_.allowSingleQuotes_) { ++ token.type_ = tokenString; ++ ok = readStringSingleQuote(); ++- break; ++- } // else fall through +++ } else { +++ // If we don't allow single quotes, this is a failure case. +++ ok = false; +++ } +++ break; ++ case '/': ++ token.type_ = tokenComment; ++ ok = readComment(); ++diff --git a/test/data/fail_invalid_quote.json b/test/data/fail_invalid_quote.json ++new file mode 100644 ++index 0000000..0dd76ed ++--- /dev/null +++++ b/test/data/fail_invalid_quote.json ++@@ -0,0 +1 @@ +++{'//this is bad JSON.'} ++-- ++2.40.0.windows.1 ++ +diff --git a/0002-sync-avoid-isprint-because-it-is-locale-specific.patch b/0002-sync-avoid-isprint-because-it-is-locale-specific.patch +new file mode 100644 +index 0000000..c051e5a +--- /dev/null ++++ b/0002-sync-avoid-isprint-because-it-is-locale-specific.patch +@@ -0,0 +1,40 @@ ++From 08fec11ca29e0bce7d8cece6d2ab62d0604b2c9a Mon Sep 17 00:00:00 2001 ++From: zhangzhangxin ++Date: Fri, 28 Apr 2023 11:54:36 +0800 ++Subject: [PATCH] sync:avoid isprint, because it is locale specific ++ ++Signed-off-by: zhangzhangxin ++--- ++ src/lib_json/json_writer.cpp | 6 +++--- ++ 1 file changed, 3 insertions(+), 3 deletions(-) ++ ++diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp ++index 03a777f..8bf02db 100644 ++--- a/src/lib_json/json_writer.cpp +++++ b/src/lib_json/json_writer.cpp ++@@ -175,11 +175,11 @@ String valueToString(double value, unsigned int precision, ++ ++ String valueToString(bool value) { return value ? "true" : "false"; } ++ ++-static bool isAnyCharRequiredQuoting(char const* s, size_t n) { +++static bool doesAnyCharRequireEscaping(char const* s, size_t n) { ++ assert(s || !n); ++ ++ return std::any_of(s, s + n, [](unsigned char c) { ++- return c == '\\' || c == '"' || !std::isprint(c); +++ return c == '\\' || c == '"' || c < 0x20 || c > 0x7F; ++ }); ++ } ++ ++@@ -275,7 +275,7 @@ static String valueToQuotedStringN(const char* value, unsigned length, ++ if (value == nullptr) ++ return ""; ++ ++- if (!isAnyCharRequiredQuoting(value, length)) +++ if (!doesAnyCharRequireEscaping(value, length)) ++ return String("\"") + value + "\""; ++ // We have to walk value and escape any special characters. ++ // Appending to String is not efficient, but this should be rare. ++-- ++2.40.0.windows.1 ++ +diff --git a/include/json/value.h b/include/json/value.h +index dffc51a..df1eba6 100644 +--- a/include/json/value.h ++++ b/include/json/value.h +@@ -342,6 +342,7 @@ public: + Value(const StaticString& value); + Value(const String& value); + Value(bool value); ++ Value(std::nullptr_t ptr) = delete; + Value(const Value& other); + Value(Value&& other); + ~Value(); +-- +2.40.0.windows.1 + diff --git a/jsoncpp.spec b/jsoncpp.spec index b9279e8..1ee8f52 100644 --- a/jsoncpp.spec +++ b/jsoncpp.spec @@ -1,6 +1,6 @@ Name: jsoncpp Version: 1.9.3 -Release: 4 +Release: 5 Summary: JSON C++ library License: Public Domain or MIT URL: https://github.com/open-source-parsers/jsoncpp @@ -8,6 +8,7 @@ Source0: https://github.com/open-source-parsers/jsoncpp/archive/%{version BuildRequires: gcc-c++ cmake >= 3.1 python3-devel Patch0: 0001-sync-Issue-1182-Fix-fuzzing-bug.patch Patch1: 0002-sync-avoid-isprint-because-it-is-locale-specific.patch +Patch2: 0003-sync-Add-nullptr-Json-Value-constructor.patch %description JsonCpp is a C++ library that allows manipulating JSON values, @@ -89,6 +90,9 @@ hardlink -cfv %{buildroot}%{_docdir}/%{name} %changelog +* Fri Apr 28 2023 zhangxin - 1.9.3-5 +- Add nullptr Json::Value constructor + * Fri Apr 28 2023 zhangxin - 1.9.3-4 - avoid isprint, because it is locale specific -- Gitee From dac9c20a2288c073be0a9cc157ca4bad3570775d Mon Sep 17 00:00:00 2001 From: zhangzhangxin Date: Fri, 28 Apr 2023 17:43:03 +0800 Subject: [PATCH 2/3] sync:Add nullptr Json::Value constructor Signed-off-by: zhangzhangxin --- ...c-Add-nullptr-Json-Value-constructor.patch | 104 +----------------- 1 file changed, 4 insertions(+), 100 deletions(-) diff --git a/0003-sync-Add-nullptr-Json-Value-constructor.patch b/0003-sync-Add-nullptr-Json-Value-constructor.patch index a1a2494..8ee15d8 100644 --- a/0003-sync-Add-nullptr-Json-Value-constructor.patch +++ b/0003-sync-Add-nullptr-Json-Value-constructor.patch @@ -1,109 +1,13 @@ -From 8cd6c2a6db9c35e44d7551d6f2ed3acaf29f1777 Mon Sep 17 00:00:00 2001 +From 8009add0cae666b14677376269b2b2f810ede318 Mon Sep 17 00:00:00 2001 From: zhangzhangxin -Date: Fri, 28 Apr 2023 14:25:44 +0800 +Date: Fri, 28 Apr 2023 15:49:46 +0800 Subject: [PATCH] sync:Add nullptr Json::Value constructor Signed-off-by: zhangzhangxin --- - 0001-sync-Issue-1182-Fix-fuzzing-bug.patch | 40 +++++++++++++++++++ - ...sprint-because-it-is-locale-specific.patch | 40 +++++++++++++++++++ - include/json/value.h | 1 + - 3 files changed, 81 insertions(+) - create mode 100644 0001-sync-Issue-1182-Fix-fuzzing-bug.patch - create mode 100644 0002-sync-avoid-isprint-because-it-is-locale-specific.patch + include/json/value.h | 1 + + 1 file changed, 1 insertion(+) -diff --git a/0001-sync-Issue-1182-Fix-fuzzing-bug.patch b/0001-sync-Issue-1182-Fix-fuzzing-bug.patch -new file mode 100644 -index 0000000..79374d4 ---- /dev/null -+++ b/0001-sync-Issue-1182-Fix-fuzzing-bug.patch -@@ -0,0 +1,40 @@ -+From 0398d63a8435d5b8f71f07aa8c42e7d65815f97e Mon Sep 17 00:00:00 2001 -+From: zhangzhangxin -+Date: Fri, 28 Apr 2023 10:50:40 +0800 -+Subject: [PATCH] sync:Issue 1182: Fix fuzzing bug -+ -+Signed-off-by: zhangzhangxin -+--- -+ src/lib_json/json_reader.cpp | 7 +++++-- -+ test/data/fail_invalid_quote.json | 1 + -+ 2 files changed, 6 insertions(+), 2 deletions(-) -+ create mode 100644 test/data/fail_invalid_quote.json -+ -+diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp -+index 23cbe60..19922a8 100644 -+--- a/src/lib_json/json_reader.cpp -++++ b/src/lib_json/json_reader.cpp -+@@ -1175,8 +1175,11 @@ bool OurReader::readToken(Token& token) { -+ if (features_.allowSingleQuotes_) { -+ token.type_ = tokenString; -+ ok = readStringSingleQuote(); -+- break; -+- } // else fall through -++ } else { -++ // If we don't allow single quotes, this is a failure case. -++ ok = false; -++ } -++ break; -+ case '/': -+ token.type_ = tokenComment; -+ ok = readComment(); -+diff --git a/test/data/fail_invalid_quote.json b/test/data/fail_invalid_quote.json -+new file mode 100644 -+index 0000000..0dd76ed -+--- /dev/null -++++ b/test/data/fail_invalid_quote.json -+@@ -0,0 +1 @@ -++{'//this is bad JSON.'} -+-- -+2.40.0.windows.1 -+ -diff --git a/0002-sync-avoid-isprint-because-it-is-locale-specific.patch b/0002-sync-avoid-isprint-because-it-is-locale-specific.patch -new file mode 100644 -index 0000000..c051e5a ---- /dev/null -+++ b/0002-sync-avoid-isprint-because-it-is-locale-specific.patch -@@ -0,0 +1,40 @@ -+From 08fec11ca29e0bce7d8cece6d2ab62d0604b2c9a Mon Sep 17 00:00:00 2001 -+From: zhangzhangxin -+Date: Fri, 28 Apr 2023 11:54:36 +0800 -+Subject: [PATCH] sync:avoid isprint, because it is locale specific -+ -+Signed-off-by: zhangzhangxin -+--- -+ src/lib_json/json_writer.cpp | 6 +++--- -+ 1 file changed, 3 insertions(+), 3 deletions(-) -+ -+diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp -+index 03a777f..8bf02db 100644 -+--- a/src/lib_json/json_writer.cpp -++++ b/src/lib_json/json_writer.cpp -+@@ -175,11 +175,11 @@ String valueToString(double value, unsigned int precision, -+ -+ String valueToString(bool value) { return value ? "true" : "false"; } -+ -+-static bool isAnyCharRequiredQuoting(char const* s, size_t n) { -++static bool doesAnyCharRequireEscaping(char const* s, size_t n) { -+ assert(s || !n); -+ -+ return std::any_of(s, s + n, [](unsigned char c) { -+- return c == '\\' || c == '"' || !std::isprint(c); -++ return c == '\\' || c == '"' || c < 0x20 || c > 0x7F; -+ }); -+ } -+ -+@@ -275,7 +275,7 @@ static String valueToQuotedStringN(const char* value, unsigned length, -+ if (value == nullptr) -+ return ""; -+ -+- if (!isAnyCharRequiredQuoting(value, length)) -++ if (!doesAnyCharRequireEscaping(value, length)) -+ return String("\"") + value + "\""; -+ // We have to walk value and escape any special characters. -+ // Appending to String is not efficient, but this should be rare. -+-- -+2.40.0.windows.1 -+ diff --git a/include/json/value.h b/include/json/value.h index dffc51a..df1eba6 100644 --- a/include/json/value.h -- Gitee From 6772438f78820d60c21235c598a50da24a269d90 Mon Sep 17 00:00:00 2001 From: zhangzhangxin Date: Fri, 28 Apr 2023 18:01:36 +0800 Subject: [PATCH 3/3] sync:Fix generation of pkg-config file with absolute includedir/libdir. Signed-off-by: zhangzhangxin --- ...ion-of-pkg-config-file-with-absolute.patch | 99 +++++++++++++++++++ jsoncpp.spec | 6 +- 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 0004-sync-Fix-generation-of-pkg-config-file-with-absolute.patch diff --git a/0004-sync-Fix-generation-of-pkg-config-file-with-absolute.patch b/0004-sync-Fix-generation-of-pkg-config-file-with-absolute.patch new file mode 100644 index 0000000..4dcc824 --- /dev/null +++ b/0004-sync-Fix-generation-of-pkg-config-file-with-absolute.patch @@ -0,0 +1,99 @@ +From 85f6fdf884f45b08317b8d05ecf10fbf45563ea7 Mon Sep 17 00:00:00 2001 +From: zhangzhangxin +Date: Fri, 28 Apr 2023 16:06:48 +0800 +Subject: [PATCH] sync:Fix generation of pkg-config file with absolute + includedir/libdir + +Signed-off-by: zhangzhangxin +--- + .gitignore | 1 - + CMakeLists.txt | 7 +++++++ + cmake/JoinPaths.cmake | 23 +++++++++++++++++++++++ + pkg-config/jsoncpp.pc.in | 4 ++-- + 4 files changed, 32 insertions(+), 3 deletions(-) + create mode 100644 cmake/JoinPaths.cmake + +diff --git a/.gitignore b/.gitignore +index 91121c2..68f40b0 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -28,7 +28,6 @@ + + # CMake-generated files: + CMakeFiles/ +-*.cmake + /pkg-config/jsoncpp.pc + jsoncpp_lib_static.dir/ + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 01b8c9d..7e64bec 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -49,6 +49,8 @@ if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES) + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage.") + endif() + ++set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") ++ + # --------------------------------------------------------------------------- + # use ccache if found, has to be done before project() + # --------------------------------------------------------------------------- +@@ -146,6 +148,11 @@ if(JSONCPP_WITH_WARNING_AS_ERROR) + endif() + + if(JSONCPP_WITH_PKGCONFIG_SUPPORT) ++ include(JoinPaths) ++ ++ join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") ++ join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") ++ + configure_file( + "pkg-config/jsoncpp.pc.in" + "pkg-config/jsoncpp.pc" +diff --git a/cmake/JoinPaths.cmake b/cmake/JoinPaths.cmake +new file mode 100644 +index 0000000..148f5b6 +--- /dev/null ++++ b/cmake/JoinPaths.cmake +@@ -0,0 +1,23 @@ ++# This module provides a function for joining paths ++# known from most languages ++# ++# SPDX-License-Identifier: (MIT OR CC0-1.0) ++# Copyright 2020 Jan Tojnar ++# https://github.com/jtojnar/cmake-snips ++# ++# Modelled after Python’s os.path.join ++# https://docs.python.org/3.7/library/os.path.html#os.path.join ++# Windows not supported ++function(join_paths joined_path first_path_segment) ++ set(temp_path "${first_path_segment}") ++ foreach(current_segment IN LISTS ARGN) ++ if(NOT ("${current_segment}" STREQUAL "")) ++ if(IS_ABSOLUTE "${current_segment}") ++ set(temp_path "${current_segment}") ++ else() ++ set(temp_path "${temp_path}/${current_segment}") ++ endif() ++ endif() ++ endforeach() ++ set(${joined_path} "${temp_path}" PARENT_SCOPE) ++endfunction() +\ No newline at end of file +diff --git a/pkg-config/jsoncpp.pc.in b/pkg-config/jsoncpp.pc.in +index d4fa9ef..632a377 100644 +--- a/pkg-config/jsoncpp.pc.in ++++ b/pkg-config/jsoncpp.pc.in +@@ -1,7 +1,7 @@ + prefix=@CMAKE_INSTALL_PREFIX@ + exec_prefix=@CMAKE_INSTALL_PREFIX@ +-libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ +-includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ ++libdir=@libdir_for_pc_file@ ++includedir=@includedir_for_pc_file@ + + Name: jsoncpp + Description: A C++ library for interacting with JSON +-- +2.40.0.windows.1 + diff --git a/jsoncpp.spec b/jsoncpp.spec index 1ee8f52..bc5a62e 100644 --- a/jsoncpp.spec +++ b/jsoncpp.spec @@ -1,6 +1,6 @@ Name: jsoncpp Version: 1.9.3 -Release: 5 +Release: 6 Summary: JSON C++ library License: Public Domain or MIT URL: https://github.com/open-source-parsers/jsoncpp @@ -9,6 +9,7 @@ BuildRequires: gcc-c++ cmake >= 3.1 python3-devel Patch0: 0001-sync-Issue-1182-Fix-fuzzing-bug.patch Patch1: 0002-sync-avoid-isprint-because-it-is-locale-specific.patch Patch2: 0003-sync-Add-nullptr-Json-Value-constructor.patch +Patch3: 0004-sync-Fix-generation-of-pkg-config-file-with-absolute.patch %description JsonCpp is a C++ library that allows manipulating JSON values, @@ -90,6 +91,9 @@ hardlink -cfv %{buildroot}%{_docdir}/%{name} %changelog +* Fri Apr 28 2023 zhangxin - 1.9.3-6 +- Fix generation of pkg-config file with absolute includedir/libdir. + * Fri Apr 28 2023 zhangxin - 1.9.3-5 - Add nullptr Json::Value constructor -- Gitee