Commit Graph

12 Commits

Author SHA1 Message Date
Kyle Evans
09078445fb vis(3): need <stdint.h> for SIZE_MAX 2023-08-13 00:28:12 -05:00
Kyle Evans
ea46e63863 Merge commit 'acb089b983171667467adc66f56a723b609ed22e' into kbsd/vis
Highlights:
- Some style fixes
- Bumped mbbuf in istrsenvisx() to MB_LEN_MAX to avoid VLAs
- mbslength cannot go negative, so make it unsigned
- Further bounds checking & fix an additional overrun, with dlen == 0
- Avoid duplicate call to wcslen(start)
2023-08-13 00:23:02 -05:00
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
Alex Richardson
1a2f06d0f2 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
2021-06-16 16:27:13 +01:00
Brooks Davis
ff88ef4183 Update vis(3) the latest from NetBSD.
This adds VIS_DQ for compatiblity with OpenBSD.

Correct by an off-by-one error and a read buffer overflow detected using
asan.

MFC after:	1 day
2017-11-28 01:35:28 +00:00
Enji Cooper
b7b9ebba77 vis(3): delete spurious .Pp macro
MFC after:	2 weeks
Reported by:	make manlint
Sponsored by:	Dell EMC Isilon
2017-05-23 07:00:46 +00:00
Bryan Drewery
f0a6d7e204 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
2016-12-06 17:05:02 +00:00
Brooks Davis
8dfeba04eb Update to a June 8th snapshot of (un)vis form NetBSD.
This adds stravis() and some new encoding flags VIS_SHELL, VIS_META,
and VIS_NOLOCALE.

Assorted cleanups and fixes includeing a manpage typo[0].

PR:		210013 [0]
Submitted by:	pi [0]
2016-06-08 18:21:27 +00:00
Brooks Davis
ac25e23856 Merge from NetBSD:
PR/49185: Conrad Meyer: strvisx: Handle zero-length input strings
gracefully.  (don't abuse 0 to mean compute string length internally)

PR:		193447
Submitted by:	Conrad Meyer <conrad.meyer@isilon.com>
MFC after:	1 month
2014-09-08 19:26:21 +00:00
Sergey Kandaurov
492a99a2fc Restore the Nx macro lost in transit.
This matches upstream.

PR:		186205
Submitted by:	naddy
MFC after:	3 days
2014-01-29 11:39:58 +00:00
Brooks Davis
778c12a624 Update to the latest (un)vis(3) sources from NetBSD. This adds
multibyte support[0] and the new functions strenvisx and strsenvisx.

Add MLINKS for vis(3) functions add by this and the initial import from
NetBSD[1].

PR:		bin/166364, bin/175418
Submitted by:	"J.R. Oldroyd" <fbsd@opal.com>[0]
		stefanf[1]
Obtained from:	NetBSD
MFC after:	2 weeks
2013-03-14 23:51:47 +00:00
Brooks Davis
8ccca1222d Replace our implementation of the vis(3) and unvis(3) APIs with
NetBSD's.  This output size limited versions of vis and unvis functions
as well as a set of vis variants that allow arbitrary characters to be
specified for encoding.

Finally, MIME Quoted-Printable encoding as described in RFC 2045 is
supported.
2012-12-18 16:37:24 +00:00