git: d0f4e583bff6 - main - efivar: handle error when reading --fromfile
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 25 Feb 2022 15:31:08 UTC
The branch main has been updated by vangyzen: URL: https://cgit.FreeBSD.org/src/commit/?id=d0f4e583bff67e2bdd816549c460da6daa3f67b1 commit d0f4e583bff67e2bdd816549c460da6daa3f67b1 Author: Eric van Gyzen <vangyzen@FreeBSD.org> AuthorDate: 2022-02-23 18:15:34 +0000 Commit: Eric van Gyzen <vangyzen@FreeBSD.org> CommitDate: 2022-02-25 15:30:29 +0000 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 eb9a6e0257c8..5bdf0c11a488 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);