[libcamera-devel] [PATCH 1/4] cam: options: fix access to uninit variable
Kieran Bingham
kieran.bingham at ideasonboard.com
Wed Oct 7 11:37:41 CEST 2020
Hi Tomi,
On 07/10/2020 10:22, Tomi Valkeinen wrote:
> operator[] doesn't check if the option exists in the values_ map, so it
> can return a pointer to location outside the map.
>
> Fix by returning an empty OptionValue if the option is not found.
>
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen at iki.fi>
> ---
> src/cam/options.cpp | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/src/cam/options.cpp b/src/cam/options.cpp
> index 77b3cc1..8fc1c42 100644
> --- a/src/cam/options.cpp
> +++ b/src/cam/options.cpp
> @@ -61,7 +61,12 @@ bool OptionsBase<T>::isSet(const T &opt) const
> template<typename T>
> const OptionValue &OptionsBase<T>::operator[](const T &opt) const
> {
> - return values_.find(opt)->second;
> + static const OptionValue s_empty;
> +
> + auto it = values_.find(opt);
> + if (it != values_.end())
> + return it->second;
> + return s_empty;
> }
>
> template<typename T>
>
--
Regards
--
Kieran
More information about the libcamera-devel
mailing list