Searched hist:"2 f489a509e615c46be6f7c6aa7cea161f50f18af" (Results 1 – 2 of 2) sorted by relevance
/freebsd/contrib/netbsd-tests/lib/libc/gen/ |
H A D | t_vis.c | diff 2f489a509e615c46be6f7c6aa7cea161f50f18af Tue Aug 08 19:01:28 CEST 2023 Kyle Evans <kevans@FreeBSD.org> libc: fix some overflow scenarios in vis(3)
The previous incarnation of this would call wcrtomb() on the destination buffer, and only check for overflow *after* it's happened. Additionally, the conversion error / VIS_NOLOCALE path also didn't check for overflow, and the overflow check at the end didn't account for the fact that we still need to write a NUL terminator afterward.
Start by only doing the multibyte conversion into mbdst directly if we have enough buffer space to guarantee it'll fit. An additional MB_CUR_MAX buffer has been stashed on the stack to write into if we're cutting it close at the end of the buffer, since we don't really have a good way to determine the length of the wchar_t without just doing the conversion. We'll do the conversion into the buffer that's guaranteed to fit, then copy it over if the copy won't overflow.
The byte-for-byte overflow is a little bit easier, as we simply check for overflow with each byte written and make sure we can still NUL terminate after.
Tests added to exercise these edge cases.
Reviewed by: des Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D41328
|
/freebsd/contrib/libc-vis/ |
H A D | vis.c | diff 2f489a509e615c46be6f7c6aa7cea161f50f18af Tue Aug 08 19:01:28 CEST 2023 Kyle Evans <kevans@FreeBSD.org> libc: fix some overflow scenarios in vis(3)
The previous incarnation of this would call wcrtomb() on the destination buffer, and only check for overflow *after* it's happened. Additionally, the conversion error / VIS_NOLOCALE path also didn't check for overflow, and the overflow check at the end didn't account for the fact that we still need to write a NUL terminator afterward.
Start by only doing the multibyte conversion into mbdst directly if we have enough buffer space to guarantee it'll fit. An additional MB_CUR_MAX buffer has been stashed on the stack to write into if we're cutting it close at the end of the buffer, since we don't really have a good way to determine the length of the wchar_t without just doing the conversion. We'll do the conversion into the buffer that's guaranteed to fit, then copy it over if the copy won't overflow.
The byte-for-byte overflow is a little bit easier, as we simply check for overflow with each byte written and make sure we can still NUL terminate after.
Tests added to exercise these edge cases.
Reviewed by: des Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D41328
|