Fix an out-of-bounds write when a zero-length buffer is passed.
Found with ttyname_test and CHERI bounds checking. Reviewed by: emaste Obtained from: CheriBSD MFC after: 1 week Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D10377
This commit is contained in:
parent
33c72b24de
commit
8439a7220d
@ -61,6 +61,10 @@ ttyname_r(int fd, char *buf, size_t len)
|
||||
{
|
||||
size_t used;
|
||||
|
||||
/* Don't write off the end of a zero-length buffer. */
|
||||
if (len < 1)
|
||||
return (ERANGE);
|
||||
|
||||
*buf = '\0';
|
||||
|
||||
/* Must be a terminal. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user