mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-30 10:52:50 +00:00
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
(cherry picked from commit 1a2f06d0f2
)
This commit is contained in:
parent
f42db652c3
commit
c89f104c12
@ -465,7 +465,8 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
|
||||
while (mbslength > 0) {
|
||||
/* Convert one multibyte character to wchar_t. */
|
||||
if (!cerr)
|
||||
clen = mbrtowc(src, mbsrc, MB_LEN_MAX, &mbstate);
|
||||
clen = mbrtowc(src, mbsrc, MIN(mbslength, MB_LEN_MAX),
|
||||
&mbstate);
|
||||
if (cerr || clen < 0) {
|
||||
/* Conversion error, process as a byte instead. */
|
||||
*src = (wint_t)(u_char)*mbsrc;
|
||||
|
Loading…
Reference in New Issue
Block a user