git: 858c11b39cc5 - stable/13 - uefisign: fix handling of errors from child proc

From: Eric van Gyzen <vangyzen_at_FreeBSD.org>
Date: Wed, 02 Mar 2022 21:57:13 UTC
The branch stable/13 has been updated by vangyzen:

URL: https://cgit.FreeBSD.org/src/commit/?id=858c11b39cc5619371ade0ab4237cca6e9bb2060

commit 858c11b39cc5619371ade0ab4237cca6e9bb2060
Author:     Eric van Gyzen <vangyzen@FreeBSD.org>
AuthorDate: 2021-04-06 14:36:52 +0000
Commit:     Eric van Gyzen <vangyzen@FreeBSD.org>
CommitDate: 2022-03-02 21:56:29 +0000

    uefisign: fix handling of errors from child proc
    
    Close the unused pipe file descriptors so the parent will notice if
    the child exits prematurely.  Previously, the parent would block
    forever on a read from the pipe.
    
        $ uefisign -c foo.cert -k foo.key -o loader.efi loader.efi.unsigned
        uefisign: section points inside the headers
        load: 0.06  cmd: uefisign 4502 [piperd] 7.25r 0.00u 0.00s 0% 5968k
        ... _sleep+0x1be pipe_read+0x3d6 kern_readv+0x8c sys_read+0x83 ...
    
    Reviewed by:    trasz
    MFC after:      1 week
    Sponsored by:   Dell EMC Isilon
    Differential Revision:  https://reviews.freebsd.org/D29605
    
    (cherry picked from commit 9e6158d274829249322efb3767e6ac2e690cc4a9)
---
 usr.sbin/uefisign/uefisign.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/usr.sbin/uefisign/uefisign.c b/usr.sbin/uefisign/uefisign.c
index 149e90ba0e67..7eab934c3394 100644
--- a/usr.sbin/uefisign/uefisign.c
+++ b/usr.sbin/uefisign/uefisign.c
@@ -410,8 +410,12 @@ main(int argc, char **argv)
 	if (pid < 0)
 		err(1, "fork");
 
-	if (pid == 0)
+	if (pid == 0) {
+		close(pipefds[0]);
 		exit(child(inpath, outpath, pipefds[1], Vflag, vflag));
+	}
+
+	close(pipefds[1]);
 
 	if (!Vflag) {
 		certfp = checked_fopen(certpath, "r");