[libcamera-devel] [PATCH] ipa: rpi: Fix segfault when parsing invalid json file
David Plowman
david.plowman at raspberrypi.com
Thu Sep 14 11:44:46 CEST 2023
Hi Naush
Thanks for the patch.
On Thu, 14 Sept 2023 at 10:28, Naushir Patuck via libcamera-devel
<libcamera-devel at lists.libcamera.org> wrote:
>
> 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 retrive the version key.
s/retrive/retrieve/
But otherwise:
Reviewed-by: David Plowman <david.plowman at raspberrypi.com>
Thanks
David
>
> Fix this by bailing out early if the parser returns a null pointer.
>
> Signed-off-by: Naushir Patuck <naush at raspberrypi.com>
> ---
> src/ipa/rpi/controller/controller.cpp | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/src/ipa/rpi/controller/controller.cpp b/src/ipa/rpi/controller/controller.cpp
> index fa1721130783..14d245da2ce7 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<YamlObject> root = YamlParser::parse(file);
> + if (!root)
> + return -EINVAL;
> +
> double version = (*root)["version"].get<double>(1.0);
> target_ = (*root)["target"].get<std::string>("bcm2835");
>
> --
> 2.34.1
>
More information about the libcamera-devel
mailing list