From c7098685723be8a6e03cce245d23e59554723be0 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Thu, 4 Feb 2021 20:41:59 +0000 Subject: [PATCH] process substitution: improve fifo error handling (re: ab5dedde) src/cmd/ksh93/sh/args.c: sh_argprocsub(): - Fix compiler warnings with SHOPT_DEVFD on by including "io.h". - Without SHOPT_DEVFD, the FIFO code didn't consider that libast's pathtemp(3) may also fail and return null. Add a check for this. --- src/cmd/ksh93/sh/args.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cmd/ksh93/sh/args.c b/src/cmd/ksh93/sh/args.c index 5756ec412..527639d4d 100644 --- a/src/cmd/ksh93/sh/args.c +++ b/src/cmd/ksh93/sh/args.c @@ -36,8 +36,10 @@ #include "FEATURE/poll" #if SHOPT_KIA # include "shlex.h" +#endif +#if SHOPT_KIA || SHOPT_DEVFD # include "io.h" -#endif /* SHOPT_KIA */ +#endif #if SHOPT_PFSH # define PFSHOPT "P" #else @@ -701,12 +703,15 @@ struct argnod *sh_argprocsub(Shell_t *shp,struct argnod *argp) sh_pipe(pv); #else pv[0] = -1; - while((shp->fifo = pathtemp(0,0,0,"ksh.fifo",0), mkfifo(shp->fifo,0))<0) + while(shp->fifo = pathtemp(0,0,0,"ksh.fifo",0), shp->fifo && mkfifo(shp->fifo,0)<0) { if(errno==EEXIST || errno==EACCES || errno==ENOENT || errno==ENOTDIR || errno==EROFS) continue; /* lost race (name conflict or tmp dir change); try again */ - errormsg(SH_DICT,ERROR_system(128),"process substitution: FIFO creation failed"); + shp->fifo = 0; + break; } + if(!shp->fifo) + errormsg(SH_DICT,ERROR_system(128),"process substitution: FIFO creation failed"); chmod(shp->fifo,S_IRUSR|S_IWUSR); /* mkfifo + chmod works regardless of umask */ sfputr(shp->stk,shp->fifo,0); #endif /* SHOPT_DEVFD */