From 44b5a4df7413008be70368862666f06cb8de4ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 9 Aug 2026 15:47:27 +0200 Subject: [PATCH] JSONReader: fix null deref in getInt/getFloat/getBool no-default overloads These dereferenced get()'s result unconditionally, unlike the two/three-arg "OrDefault" overloads which check. Hit on externally sourced JSON: UI/Store.cpp reads the remote homebrew-store listing, UI/DriverManagerScreen.cpp reads user-supplied GPU driver package metadata - a field simply missing from either crashed the app instead of failing gracefully. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY --- Common/Data/Format/JSONReader.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Common/Data/Format/JSONReader.cpp b/Common/Data/Format/JSONReader.cpp index 3a4e947bb0..b5f11e57d9 100644 --- a/Common/Data/Format/JSONReader.cpp +++ b/Common/Data/Format/JSONReader.cpp @@ -106,7 +106,12 @@ bool JsonGet::getStringVector(std::vector *vec) const { } double JsonGet::getFloat(const char *child_name) const { - return get(child_name, JSON_NUMBER)->value.toNumber(); + const JsonNode *val = get(child_name, JSON_NUMBER); + if (!val) { + ERROR_LOG(Log::IO, "Number '%s' missing from node", child_name); + return 0.0; + } + return val->value.toNumber(); } double JsonGet::getFloat(const char *child_name, double default_value) const { @@ -117,7 +122,12 @@ double JsonGet::getFloat(const char *child_name, double default_value) const { } int JsonGet::getInt(const char *child_name) const { - return (int)get(child_name, JSON_NUMBER)->value.toNumber(); + const JsonNode *val = get(child_name, JSON_NUMBER); + if (!val) { + ERROR_LOG(Log::IO, "Number '%s' missing from node", child_name); + return 0; + } + return (int)val->value.toNumber(); } int JsonGet::getInt(const char *child_name, int default_value) const { @@ -128,7 +138,12 @@ int JsonGet::getInt(const char *child_name, int default_value) const { } bool JsonGet::getBool(const char *child_name) const { - return get(child_name)->value.getTag() == JSON_TRUE; + const JsonNode *val = get(child_name); + if (!val) { + ERROR_LOG(Log::IO, "Value '%s' missing from node", child_name); + return false; + } + return val->value.getTag() == JSON_TRUE; } bool JsonGet::getBoolOr(const char *child_name, bool default_value) const {