From 90e0fea6c6ba6294bf9438d37d74676cc53ef924 Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Thu, 14 Sep 2023 10:27:56 +0100 Subject: ipa: rpi: Fix segfault when parsing invalid json file If the json file parsing failed due to a malformed file, the root pointer would be null. This was not tested and caused a segfault when trying to use the pointer to retrieve the version key. Fix this by bailing out early if the parser returns a null pointer. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi Signed-off-by: Jacopo Mondi --- src/ipa/rpi/controller/controller.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/ipa/rpi/controller') diff --git a/src/ipa/rpi/controller/controller.cpp b/src/ipa/rpi/controller/controller.cpp index fa172113..14d245da 100644 --- a/src/ipa/rpi/controller/controller.cpp +++ b/src/ipa/rpi/controller/controller.cpp @@ -56,6 +56,9 @@ int Controller::read(char const *filename) } std::unique_ptr root = YamlParser::parse(file); + if (!root) + return -EINVAL; + double version = (*root)["version"].get(1.0); target_ = (*root)["target"].get("bcm2835"); -- cgit v1.2.1