From 67183f5822c3e28b51bb06b754e002c737feeccf Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Wed, 11 Sep 2013 22:20:30 +0200 Subject: [PATCH] Make sure we don't access outside the choices_ array in PopupMultiChoice --- ui/ui_screen.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ui/ui_screen.cpp b/ui/ui_screen.cpp index 5626e9012e..1b2c908442 100644 --- a/ui/ui_screen.cpp +++ b/ui/ui_screen.cpp @@ -205,7 +205,12 @@ UI::EventReturn PopupMultiChoice::HandleClick(UI::EventParams &e) { } void PopupMultiChoice::UpdateText() { - valueText_ = category_ ? category_->T(choices_[*value_ - minVal_]) : choices_[*value_ - minVal_]; + // Clamp the value to be safe. + if (*value_ < minVal_ || *value_ > minVal_ + numChoices_ - 1) { + valueText_ = "(invalid choice)"; // Shouldn't happen. Should be no need to translate this. + } else { + valueText_ = category_ ? category_->T(choices_[*value_ - minVal_]) : choices_[*value_ - minVal_]; + } } void PopupMultiChoice::ChoiceCallback(int num) {