From 8e6ca49687d2e10b08f024f1a4f4b384be29987b Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Wed, 7 Oct 2020 12:22:36 +0300 Subject: cam: options: fix access to uninit variable 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. Signed-off-by: Tomi Valkeinen Reviewed-by: Kieran Bingham [Kieran: Adjust s_empty naming to 'empty'] Signed-off-by: Kieran Bingham --- src/cam/options.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/cam') diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 77b3cc1f..358507ea 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -61,7 +61,12 @@ bool OptionsBase::isSet(const T &opt) const template const OptionValue &OptionsBase::operator[](const T &opt) const { - return values_.find(opt)->second; + static const OptionValue empty; + + auto it = values_.find(opt); + if (it != values_.end()) + return it->second; + return empty; } template -- cgit v1.2.1