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) {