Fix buffer underflow if sysfs file is empty

Signed-off-by: Robert Evans <evansr@google.com>

Fixes: #16028
This commit is contained in:
Robert Evans 2024-03-28 00:18:30 -04:00
parent e39e20b6dc
commit 0dd1b29034
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);