HomeFreeBSD

libc: Fix "harmless" iconv one-byte overread

Description

libc: Fix "harmless" iconv one-byte overread

Checking there are still bytes left must be done before dereferencing
the pointer, not the other way round. This is harmless on traditional
architectures since the result will immediately be thrown away, and all
callers are in separate translation units so there is no potential for
optimising based on this out-of-bounds read. However, on CHERI, pointers
are bounded, and so this will trap if fed a string that does not have a
NUL within the first len bytes.

Found by: CHERI
Reviewed by: brooks

(cherry picked from commit 6d5297569e70eb71eeb7ae5278a165d4ffb50874)

Details

Provenance
jrtc27Authored on Dec 21 2021, 10:47 PM
Parents
rG62b958cb94ea: cross-build: Add comment missing from 9e5b0d9eac5b
Branches
Unknown
Tags
Unknown