[CP] [parser][asan]: avoid heap-buffer-overflow while parser hex with odd number(e.g., 0xaaa);
This commit is contained in:
@ -505,19 +505,26 @@ void ob_parse_binary(const char *src, int64_t len, char *dest)
|
||||
if (OB_UNLIKELY(NULL == src || len <= 0 || NULL == dest)) {
|
||||
//do nothing
|
||||
} else {
|
||||
bool is_odd = false;
|
||||
if (len > 0 && len % 2 != 0)
|
||||
{
|
||||
*dest = char_int(src[0]);
|
||||
++src;
|
||||
++dest;
|
||||
is_odd = true;
|
||||
}
|
||||
const char *end = src + len -1;
|
||||
if (len == 1) {
|
||||
//do nothing.
|
||||
} else {
|
||||
//for odd number, we have copy the first char, so we should minus 2;
|
||||
const char *end = src + len - (is_odd ? 2 : 1);
|
||||
for (; src <= end; src += 2)
|
||||
{
|
||||
*dest = (char)(16*char_int(src[0]) + char_int(src[1]));
|
||||
++dest;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int64_t ob_parse_bit_string_len(int64_t len)
|
||||
|
||||
Reference in New Issue
Block a user