KASSERT(val != 0) not triggering in linux_errno.c reading outside of array
xtouqh at hotmail.com
xtouqh at hotmail.com
Tue Nov 3 11:45:41 UTC 2020
Konstantin Belousov wrote:
> On Tue, Nov 03, 2020 at 01:17:51PM +0300, xtouqh at hotmail.com wrote:
>> Hans Petter Selasky wrote:
>>> Hi,
>>>
>>> Should:
>>>
>>> for (i = 1; i < sizeof(linux_errtbl); i++) {
>>>
>>> Be:
>>>
>>> for (i = 1; i < sizeof(linux_errtbl)/sizeof(linux_errtbl[0]);
>>> i++) {
>>>
>>>
>>> Or:
>>>
>>> for (i = 1; i < (int)nitems(linux_errtbl); i++) {
>>
>> That's right, and I added the same comment in the review. My question is
>> different though -- with the issue present, KASSERT() should have triggered
>> (there are 0 values with incorrect indexes, added printf() confirms that)
>> exposing the bug, but it does not -- WHY? -- I just want to understand
>> what's going on.
>
> I think this is a poster child for the current undefined behaviour treatment
> by compilers. You are accessing beyond array last element, and compiler can
> prove it, so it allowed to do anything.
Makes sense, thank you. Just for the record, if I compile userland test
case with -O2, it behaves the same; previously I was building without
explicitly specifying optimization level, and it did "work".
More information about the freebsd-hackers
mailing list