KASSERT(val != 0) not triggering in linux_errno.c reading outside of array

xtouqh at hotmail.com xtouqh at hotmail.com
Tue Nov 3 09:46:37 UTC 2020


I'm looking at the current sys/compat/linux/linux_errno.c source, 
specifically this function: 
https://svnweb.freebsd.org/base/head/sys/compat/linux/linux_errno.c?revision=367132&view=markup#l24, 
and noticed that sizeof() usage there seems to be bogus as I mentioned 
in https://reviews.freebsd.org/D26974#inline-168811.

What I'm wondering about is why KASSERT() is not triggering there -- I 
have added the following printf() right below KASSERT() showing that we 
indeed read outside of the array, and some of the linux_errtbl[i] values 
are 0:

printf("%s:linux_errtbl[%d]=%d\n", __func__, i, linux_errtbl[i]);

But, if I add the following check before printf(), it seems to be never 
true:

if (linux_errtbl[i] == 0)
     printf("%s:linux_errtbl[%d]=%d\n", __func__, i, linux_errtbl[i]);

So how come printed values are 0, but KASSERT(value != 0) and if (value 
== 0) are never true?  I tried to reproduce this in simple userland test 
case, but the check seems to be working correctly there (though still 
reading outside of array if using sizeof() for final index).  What am I 
missing here?


More information about the freebsd-hackers mailing list