ubsan triggered for a unit test in mduptab_add because blen was SIZE_MAX

and adding it overflowed the pointer. So add a check for that in
bstr_diff2.
This commit is contained in:
leitner
2025-04-17 12:15:20 +00:00
parent 87187a76ea
commit 7586973f9f

View File

@@ -13,6 +13,12 @@ int bstr_diff2(const char* a,const char* b,size_t blen) {
A=a+5+uint32_read(a+1);
a+=5;
}
// If adding blen to b would overflow, reduce blen.
// The comparison can never get that far because the end of the
// address space is reserved for the kernel. Make sure to revisit this
// if you want to use this function in kernel space.
uintptr_t c = ~(uintptr_t)b;
if (blen > c) blen = c;
B=b+blen;
for (;;) {
if (a==A) {