From 7586973f9f44875965fb46b74cde4e33547bfe52 Mon Sep 17 00:00:00 2001 From: leitner Date: Thu, 17 Apr 2025 12:15:20 +0000 Subject: [PATCH] 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. --- bstr_diff2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bstr_diff2.c b/bstr_diff2.c index c73425e..d09ece1 100644 --- a/bstr_diff2.c +++ b/bstr_diff2.c @@ -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) {