Fix buffer underflow if sysfs file is empty

Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Jason Lee <jasonlee@lanl.gov>
Signed-off-by: Robert Evans <evansr@google.com>
Closes #16028
Closes #16035
This commit is contained in:
Robert Evans 2024-03-29 17:59:23 -04:00 committed by Tony Hutter
parent d088fb7d24
commit e0cfa1592d
1 changed files with 1 additions and 1 deletions

View File

@ -458,7 +458,7 @@ static char *zpool_sysfs_gets(char *path)
}
/* Remove trailing newline */
if (buf[count - 1] == '\n')
if (count > 0 && buf[count - 1] == '\n')
buf[count - 1] = 0;
close(fd);