From 46d3acd9d6b72e088b688c2f84aae5c0466885d8 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Fri, 11 Sep 2026 00:25:43 +0800 Subject: [PATCH] Fix LLP64 JSON bounds and fully omit disabled build dependencies --- cmake/InstallPackage.cmake | 2 ++ src/CMakeLists.txt | 4 +++- src/json.c | 9 +++++---- tests/test_json.c | 9 +++++++++ third_party/CMakeLists.txt | 3 +++ 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cmake/InstallPackage.cmake b/cmake/InstallPackage.cmake index 0c69b439..4db28a13 100644 --- a/cmake/InstallPackage.cmake +++ b/cmake/InstallPackage.cmake @@ -1,4 +1,5 @@ include(CMakePackageConfigHelpers) +if(SS_BUILD_STATIC_LIBRARY OR SS_BUILD_SHARED_LIBRARY) set(SS_SYSTEM_DEPENDENCIES "") set(SS_PC_PRIVATE "") set(private_links) @@ -68,6 +69,7 @@ configure_file(cmake/shadowsocks-libev.pc.cmake "${CMAKE_CURRENT_BINARY_DIR}/pac file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/shadowsocks-libev.pc" INPUT "${CMAKE_CURRENT_BINARY_DIR}/package/shadowsocks-libev.pc.in") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/shadowsocks-libev.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +endif() install(FILES COPYING LICENSE third_party/README.md third_party/manifest.json DESTINATION ${CMAKE_INSTALL_DATADIR}/licenses/shadowsocks-libev) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5ed737a8..32685e04 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -166,4 +166,6 @@ foreach(kind STATIC SHARED) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() endforeach() -install(FILES shadowsocks.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +if(SS_BUILD_STATIC_LIBRARY OR SS_BUILD_SHARED_LIBRARY) + install(FILES shadowsocks.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +endif() diff --git a/src/json.c b/src/json.c index 05a38b76..dd4e9d0b 100644 --- a/src/json.c +++ b/src/json.c @@ -778,9 +778,10 @@ json_value * json_parse_ex (json_settings * settings, } /* Overflow check for integer */ - long prev = top->u.integer; - if ((prev > 0 && (prev > (LONG_MAX / 10) || (prev == (LONG_MAX / 10) && (b - '0') > (LONG_MAX % 10)))) || - (prev < 0 && (prev < (LONG_MIN / 10) || (prev == (LONG_MIN / 10) && -(b - '0') < (LONG_MIN % 10))))) { + json_int_t prev = top->u.integer; + /* Digits accumulate as a positive int64_t magnitude; + * long is only 32 bits on LLP64 platforms such as Windows. */ + if (prev > (INT64_MAX / 10) || (prev == (INT64_MAX / 10) && (b - '0') > (INT64_MAX % 10))) { sprintf(error, "%d:%d: Integer too large (overflow)", line_and_col); goto e_failed; } @@ -789,7 +790,7 @@ json_value * json_parse_ex (json_settings * settings, } /* Overflow check for fraction */ - if (num_fraction > (LONG_MAX / 10) || (num_fraction == (LONG_MAX / 10) && (b - '0') > (LONG_MAX % 10))) { + if (num_fraction > (INT64_MAX / 10) || (num_fraction == (INT64_MAX / 10) && (b - '0') > (INT64_MAX % 10))) { sprintf(error, "%d:%d: Fraction too large (overflow)", line_and_col); goto e_failed; } diff --git a/tests/test_json.c b/tests/test_json.c index 7dc06549..64f87e23 100644 --- a/tests/test_json.c +++ b/tests/test_json.c @@ -139,6 +139,15 @@ test_parse_empty_array(void) int main(void) { + const char *wide_numbers = "[4294967296,9223372036854775807,-4294967296,0.4294967296]"; + json_value *wide = json_parse(wide_numbers, strlen(wide_numbers)); + assert(wide != NULL && wide->type == json_array && wide->u.array.length == 4); + assert(wide->u.array.values[0]->u.integer == INT64_C(4294967296)); + assert(wide->u.array.values[1]->u.integer == INT64_MAX); + assert(wide->u.array.values[2]->u.integer == -INT64_C(4294967296)); + assert(wide->u.array.values[3]->u.dbl > 0.4294967295 && wide->u.array.values[3]->u.dbl < 0.4294967297); + json_value_free(wide); + assert(json_parse("9223372036854775808", 19) == NULL); test_parse_simple_object(); test_parse_array(); test_parse_nested(); diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index f7b3f890..9c2413dd 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -7,6 +7,9 @@ foreach(i RANGE ${last}) foreach(field name archive sha256) string(JSON ${field} GET "${manifest}" ${i} ${field}) endforeach() + if(name STREQUAL "pcre2" AND NOT SS_ENABLE_REGEX) + continue() + endif() set(archive_path "${CMAKE_CURRENT_SOURCE_DIR}/dist/${archive}") file(SHA256 "${archive_path}" actual) if(NOT actual STREQUAL sha256)