From 8f813bb0a32c0496c512f6f2f894eef2ade4232a Mon Sep 17 00:00:00 2001 From: Johnothan King Date: Wed, 26 Aug 2020 14:19:51 -0700 Subject: [PATCH] Fix a file descriptor leak when fstat errors out with EIO (#120) src/cmd/ksh93/sh/path.c: canexecute(): - Close file descriptors inside of the err label. This fixes a file descriptor leak that occurs when open succeeds but fstat fails with EIO. The previous code only returned -1 after 'goto err', leaving the opened file descriptor inaccessible. This bugfix was backported from ksh2020: https://github.com/att/ast/commit/55cad1d --- src/cmd/ksh93/sh/path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c index 62395ab8a..507398b05 100644 --- a/src/cmd/ksh93/sh/path.c +++ b/src/cmd/ksh93/sh/path.c @@ -980,9 +980,9 @@ static int canexecute(Shell_t *shp,register char *path, int isfun) errno = EISDIR; else if((statb.st_mode&S_IXALL)==S_IXALL || sh_access(path,X_OK)>=0) return(fd); +err: if(isfun && fd>=0) sh_close(fd); -err: return(-1); }