From d75e4ccb2ee902993c88444865083008c25a21d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Thu, 6 Oct 2022 19:25:41 +0200 Subject: [PATCH] Fix OOB read when parsing empty string as float I really don't like how the only way to return with an error from ParseFloatProperty is via an exception >_> Also do a range check on airTemp only if isValid is true, otherwise it's uninitialized. --- src/gui/game/PropertyTool.cpp | 4 ++++ src/gui/options/OptionsView.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gui/game/PropertyTool.cpp b/src/gui/game/PropertyTool.cpp index ed660a319..5c56e3e4a 100644 --- a/src/gui/game/PropertyTool.cpp +++ b/src/gui/game/PropertyTool.cpp @@ -25,6 +25,10 @@ void ParseFloatProperty(String value, float &out) { + if (!value.size()) + { + throw std::out_of_range("empty string"); + } if (value.EndsWith("C")) { float v = value.SubstrFromEnd(1).ToNumber(); diff --git a/src/gui/options/OptionsView.cpp b/src/gui/options/OptionsView.cpp index 3fb2bb8a5..2e9afb14e 100644 --- a/src/gui/options/OptionsView.cpp +++ b/src/gui/options/OptionsView.cpp @@ -476,7 +476,7 @@ void OptionsView::UpdateAirTemp(String temp, bool isDefocus) ambientAirTemp->SetText(sb.Build()); } // Out of range temperatures are invalid, preview should go away - else if (airTemp < MIN_TEMP || airTemp > MAX_TEMP) + else if (isValid && (airTemp < MIN_TEMP || airTemp > MAX_TEMP)) isValid = false; // If valid, set temp