Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Mar 2022 21:57:37 GMT
From:      Eric van Gyzen <vangyzen@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 6887791e1869 - stable/13 - efivar: handle error when reading --fromfile
Message-ID:  <202203022157.222Lvbj7065467@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by vangyzen:

URL: https://cgit.FreeBSD.org/src/commit/?id=6887791e1869a70fe2ea9b20a29f066add4d6b5c

commit 6887791e1869a70fe2ea9b20a29f066add4d6b5c
Author:     Eric van Gyzen <vangyzen@FreeBSD.org>
AuthorDate: 2022-02-23 18:15:34 +0000
Commit:     Eric van Gyzen <vangyzen@FreeBSD.org>
CommitDate: 2022-03-02 21:56:31 +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
    
    (cherry picked from commit d0f4e583bff67e2bdd816549c460da6daa3f67b1)
---
 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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202203022157.222Lvbj7065467>