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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY
This commit is contained in:
Henrik RydgårdandClaude Sonnet 5 committed 2026-08-09 19:31:02 +02:00
1 parent 472ff6ac71
commit 44b5a4df74
1 file changed
+18 -3
+18 -3
View File
@@ -106,7 +106,12 @@ bool JsonGet::getStringVector(std::vector<std::string> *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 {