summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@iki.fi>2020-10-07 12:22:36 +0300
committerKieran Bingham <kieran.bingham@ideasonboard.com>2020-10-12 16:15:08 +0100
commit8e6ca49687d2e10b08f024f1a4f4b384be29987b (patch)
tree6ead6660c4645024353622f8ccc8a3d0a226afb3 /src
parent265daf6e595a390acaf1bc76207366ad774b7f6c (diff)
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 <tomi.valkeinen@iki.fi> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> [Kieran: Adjust s_empty naming to 'empty'] Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/cam/options.cpp7
1 files changed, 6 insertions, 1 deletions
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<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 empty;
+
+ auto it = values_.find(opt);
+ if (it != values_.end())
+ return it->second;
+ return empty;
}
template<typename T>