History log of /freebsd-current/contrib/libc-vis/vis.c
Revision Date Author Comments
# ea2be8ed 20-Nov-2023 Brooks Davis <brooks@FreeBSD.org>

Remove __FBSDID from netbsd libc sources

I added them per then-current practice when I imported them, but now
they are just gratuious local diffs.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D42686


# db94e7c3 20-Nov-2023 Brooks Davis <brooks@FreeBSD.org>

vis: relocate _DIAGASSERT() define

Other similar files from NetBSD define it unconditionally as a local
diff.

Reviewed by: imp (as part of D42686)


# 09078445 12-Aug-2023 Kyle Evans <kevans@FreeBSD.org>

vis(3): need <stdint.h> for SIZE_MAX


# 2f489a50 07-Aug-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


# 1a2f06d0 16-Jun-2021 Alex Richardson <arichardson@FreeBSD.org>

vis(3): avoid out-of-bounds stack buffer reads

I found this while running kdump(1) on a CheriBSD system due to a
capability length violation when printing the /etc/libmap.conf read()
system call: it crashed immediately after printing the first line.

Found by: CHERI
Reviewed By: jhb
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D30771


# f0a6d7e2 06-Dec-2016 Bryan Drewery <bdrewery@FreeBSD.org>

strvis(3): Avoid internal state of multibyte functions being tainted.

The mbtoc(3) and wctomb(3) functions use internal state which may be
tainted before the call to strvis(3). In this context we can just use
the thread-safe versions mbrtoc(3) and wcrtomb(3) which allow passing
our own state from our stack.

MFC after: 2 weeks
Sponsored by: Dell EMC Isilon