From 9ba7a470ad98b689da9a15af1c215178739b042c Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Wed, 31 Aug 2022 23:04:48 +0300 Subject: [PATCH] p18: get-rated: fix parsing of invalid response Sometimes (my guess is when AC input line is connected) get-rated (^P007PIRI request) returns additional field in the end. On my device it's two bytes, '00' (0x30 0x30). It shouldn't be there as per documentation (but you know how accurate these chinese docs can be, right?) and, as of now, I have no clue what that means. --- src/p18/response.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/p18/response.cc b/src/p18/response.cc index 2a3f78c..af9e490 100644 --- a/src/p18/response.cc +++ b/src/p18/response.cc @@ -8,6 +8,7 @@ #include "response.h" #include "exceptions.h" +#include "../logging.h" #define RETURN_TABLE(...) \ return std::shared_ptr>( \ @@ -89,6 +90,12 @@ std::vector GetResponse::getList(std::vector itemLengt // check each item's length for (int i = 0; i < list.size(); i++) { + if (i >= itemLengths.size()) { + myerr << "while parsing " << demangle_type_name(typeid(*this).name()) + << ": item " << i << " is not expected"; + break; + } + if (!itemLengths[i].validate(list[i].size())) { std::ostringstream error; error << "while parsing " << demangle_type_name(typeid(*this).name());