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.
This commit is contained in:
Tamás Bálint Misius 2022-10-06 19:25:41 +02:00
parent a8d2b269b1
commit d75e4ccb2e
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 5 additions and 1 deletions

View File

@ -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<float>();

View File

@ -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