提交 73b10be4 编写于 作者: M Monk-Liu 提交者: ob-robot

[CP] [parser][asan]: avoid heap-buffer-overflow while parser hex with odd number(e.g., 0xaaa);

上级 a09570ce
......@@ -505,17 +505,24 @@ 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;
for (; src <= end; src += 2)
{
*dest = (char)(16*char_int(src[0]) + char_int(src[1]));
++dest;
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;
}
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册