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 <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
This commit is contained in:
Naushir Patuck 2023-09-14 10:27:56 +01:00 committed by Jacopo Mondi
parent 7127954aaa
commit 90e0fea6c6

View file

@ -56,6 +56,9 @@ int Controller::read(char const *filename)
}
std::unique_ptr<YamlObject> root = YamlParser::parse(file);
if (!root)
return -EINVAL;
double version = (*root)["version"].get<double>(1.0);
target_ = (*root)["target"].get<std::string>("bcm2835");