From 699ee88b5bae7980316644987df10678d75ea9ce Mon Sep 17 00:00:00 2001 From: john30 Date: Wed, 31 Dec 2014 09:59:54 +0100 Subject: [PATCH] fixed bounds check for time types --- src/lib/ebus/data.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/ebus/data.cpp b/src/lib/ebus/data.cpp index 2b7ba4e4..6d5e65a1 100644 --- a/src/lib/ebus/data.cpp +++ b/src/lib/ebus/data.cpp @@ -487,7 +487,7 @@ result_t StringDataField::readSymbols(SymbolString& input, { size_t start = 0, count = m_length; int incr = 1; - unsigned char ch, last = 0; + unsigned char ch, last = 0, hour = 0; if (baseOffset + m_length > input.size()) { return RESULT_ERR_INVALID_POS; @@ -552,7 +552,12 @@ result_t StringDataField::readSymbols(SymbolString& input, else ch = (ch % 6) * 10; // minutes } - if ((i == 0 && ch > 24) || (i > 0 && (ch > 59 || (last == 24 && ch > 0) ))) + if (i == 0) { + if (ch > 24) + return RESULT_ERR_OUT_OF_RANGE; // invalid hour + hour = ch; + } + else if (ch > 59 || (hour == 24 && ch > 0)) return RESULT_ERR_OUT_OF_RANGE; // invalid time if (i > 0) output << ":";