From d0f4e583bff67e2bdd816549c460da6daa3f67b1 Mon Sep 17 00:00:00 2001 From: Eric van Gyzen Date: Wed, 23 Feb 2022 12:15:34 -0600 Subject: [PATCH] efivar: handle error when reading --fromfile The result of read() was stored in an unsigned variable, so the test for a negative value would never work. While I'm here, print a better error message for an empty file, omitting the misleading errno message. Reported by: Coverity MFC after: 1 week Sponsored by: Dell EMC Isilon --- usr.sbin/efivar/efivar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/usr.sbin/efivar/efivar.c b/usr.sbin/efivar/efivar.c index eb9a6e0257c..5bdf0c11a48 100644 --- a/usr.sbin/efivar/efivar.c +++ b/usr.sbin/efivar/efivar.c @@ -239,8 +239,10 @@ print_var(efi_guid_t *guid, char *name) if (data == NULL) rep_err(1, "malloc"); datalen = read(fd, data, 64 * 1024); - if (datalen <= 0) + if ((ssize_t)datalen < 0) rep_err(1, "read"); + if (datalen == 0) + rep_errx(1, "empty file"); close(fd); } else { rv = efi_get_variable(*guid, name, &data, &datalen, &att);