From e0cfa1592da065fb0e0ba7579ea4d152ce099323 Mon Sep 17 00:00:00 2001 From: Robert Evans Date: Fri, 29 Mar 2024 17:59:23 -0400 Subject: [PATCH] Fix buffer underflow if sysfs file is empty Reviewed-by: Alexander Motin Reviewed-by: Tony Hutter Reviewed-by: Jason Lee Signed-off-by: Robert Evans Closes #16028 Closes #16035 --- cmd/zpool/os/linux/zpool_vdev_os.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/zpool/os/linux/zpool_vdev_os.c b/cmd/zpool/os/linux/zpool_vdev_os.c index 006a3a7d8e..80627b5821 100644 --- a/cmd/zpool/os/linux/zpool_vdev_os.c +++ b/cmd/zpool/os/linux/zpool_vdev_os.c @@ -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);