diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-08-31 23:04:48 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-08-31 23:41:06 +0300 |
commit | 9ba7a470ad98b689da9a15af1c215178739b042c (patch) | |
tree | 4a6b89eb8b3dbae2e49c8de1f0558926e38cb393 /src | |
parent | 750297157d8c21f67eb57a1afe30286c1571eb12 (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/p18/response.cc | 7 |
1 files changed, 7 insertions, 0 deletions
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<formatter::Table<VariantHolder>>( \ @@ -89,6 +90,12 @@ std::vector<std::string> GetResponse::getList(std::vector<FieldLength> 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()); |