freebsd-dev/contrib/netbsd-tests
Kyle Evans 2f489a509e 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
2023-08-08 12:01:52 -05:00
..
bin Add testcases for cat -b 2017-06-06 21:50:00 +00:00
crypto Upgrade NetBSD tests to 01.11.2017_23.20 snapshot 2017-01-13 03:33:57 +00:00
dev Merge in changes from ^/vendor/NetBSD/tests/dist@r313245 2017-02-04 18:20:07 +00:00
fs tmpfs tests: check for built-in tmpfs module 2020-10-02 00:52:31 +00:00
games Restore pathing for factor(1), which unnecessarily diverged in r278616 2016-12-03 03:13:32 +00:00
include Merge content currently under test from ^/vendor/NetBSD/tests/dist/@r312123 2017-01-14 06:49:17 +00:00
ipf
kernel sysv test: properly wait for children 2022-05-13 11:38:26 -05:00
lib libc: fix some overflow scenarios in vis(3) 2023-08-08 12:01:52 -05:00
libexec/ld.elf_so Merge content currently under test from ^/vendor/NetBSD/tests/dist/@r312123 2017-01-14 06:49:17 +00:00
modules Merge content currently under test from ^/vendor/NetBSD/tests/dist/@r312123 2017-01-14 06:49:17 +00:00
net Merge in changes from ^/vendor/NetBSD/tests/dist@r313245 2017-02-04 18:20:07 +00:00
rump Merge content currently under test from ^/vendor/NetBSD/tests/dist/@r312123 2017-01-14 06:49:17 +00:00
sbin newfs_msdos: connect the ATF test from NetBSD 2022-02-16 09:56:16 -06:00
share
sys Merge content currently under test from ^/vendor/NetBSD/tests/dist/@r312123 2017-01-14 06:49:17 +00:00
usr.bin sort: Make NetBSD sort tests compatible with our sort 2021-05-13 09:33:47 -04:00
usr.sbin mtree: Fix -f -f not considering type changes. 2019-09-12 18:44:48 +00:00
FREEBSD-upgrade
h_macros.h Upgrade NetBSD tests to 01.11.2017_23.20 snapshot 2017-01-13 03:33:57 +00:00