hexdecoct: fix NULL pointer dereferences in hexmem()

Fixes oss-fuzz#54090 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54090).

Fixes #25655.
This commit is contained in:
Yu Watanabe
2022-12-09 04:55:47 +09:00
parent 45655e776f
commit 7d34567444
3 changed files with 22 additions and 1 deletions
+3 -1
View File
@@ -59,11 +59,13 @@ char *hexmem(const void *p, size_t l) {
const uint8_t *x;
char *r, *z;
assert(p || l == 0);
z = r = new(char, l * 2 + 1);
if (!r)
return NULL;
for (x = p; x < (const uint8_t*) p + l; x++) {
for (x = p; x && x < (const uint8_t*) p + l; x++) {
*(z++) = hexchar(*x >> 4);
*(z++) = hexchar(*x & 15);
}