Fixed crash on abrupt end of data.

pull/22/head
weetmuts 2019-03-15 14:21:50 +01:00
rodzic 6ad054aa23
commit 113b5ace28
3 zmienionych plików z 7 dodań i 9 usunięć

Wyświetl plik

@ -87,7 +87,7 @@ bool parseDV(Telegram *t,
// Since the data does not have the difvifs.
data_has_difvifs = false;
format_end = *format+format_len;
string s = bin2hex(*format, format_len);
string s = bin2hex(*format, format_end, format_len);
debug("(dvparser) using format \"%s\"\n", s.c_str());
}
@ -247,24 +247,22 @@ bool parseDV(Telegram *t,
DEBUG_PARSER("(dvparser debug) remaining data %d len=%d\n", remaining, datalen);
if (remaining < datalen) {
debug("(dvparser) warning: unexpected end of data\n");
datalen = remaining;
datalen = remaining-1;
}
// Skip the length byte in the variable length data.
if (variable_length) {
t->addExplanation(data, 1, "%02X varlen=%d", datalen, datalen);
}
string value = bin2hex(data, datalen);
string value = bin2hex(data, data_end, datalen);
int offset = start_parse_here+data-data_start;
(*values)[key] = { offset, DVEntry(vif&0x7f, storage_nr, tariff, subunit, value) };
if (value.length() > 0) {
assert(data != databytes.end());
assert(data+datalen <= databytes.end());
// This call increments data with datalen.
t->addExplanation(data, datalen, "%s", value.c_str());
DEBUG_PARSER("(dvparser debug) data \"%s\"\n\n", value.c_str());
}
if (remaining == datalen) {
if (remaining == datalen || data == databytes.end()) {
// We are done here!
break;
}

Wyświetl plik

@ -126,9 +126,9 @@ std::string bin2hex(vector<uchar> &target) {
return str;
}
std::string bin2hex(vector<uchar>::iterator data, int len) {
std::string bin2hex(vector<uchar>::iterator data, vector<uchar>::iterator end, int len) {
std::string str;
while (len-- > 0) {
while (data != end && len-- > 0) {
const char ch = *data;
data++;
str.append(&hex[(ch & 0xF0) >> 4], 1);

Wyświetl plik

@ -35,7 +35,7 @@ bool hex2bin(const char* src, std::vector<uchar> *target);
bool hex2bin(std::string &src, std::vector<uchar> *target);
bool hex2bin(std::vector<uchar> &src, std::vector<uchar> *target);
std::string bin2hex(std::vector<uchar> &target);
std::string bin2hex(std::vector<uchar>::iterator data, int len);
std::string bin2hex(std::vector<uchar>::iterator data, std::vector<uchar>::iterator end, int len);
void strprintf(std::string &s, const char* fmt, ...);
// Return for example: 2010-03-21
std::string strdate(struct tm *date);