bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bad leaks file fd to child processes


From: Greg Wooledge
Subject: Re: Bad leaks file fd to child processes
Date: Mon, 28 Nov 2022 17:18:35 -0500

On Mon, Nov 28, 2022 at 05:00:28PM -0500, Dale R. Worley wrote:
> Alexey via Bug reports for the GNU Bourne Again SHell <bug-bash@gnu.org>
> > Same behavior was in bash 4.4 (as well as now in bash 5.2):
> >
> > # echo $BASH_VERSION
> > 4.4.0(1)-release
> > # exec 66</etc/hosts
> > # pvs
> > File descriptor 66 (/etc/hosts) leaked on pvs invocation. Parent PID 
> > 1057606: ./bash
> >
> > But we use the fact tat bash doesn't close FD for example to preliminary 
> > open log file for utility that we will `exec' later.
> > Unfortunately bash doesn't provide any fcntl() mechanism to control FD 
> > flags.
> > It'll be great to have  ability to manage CLOEXEC or any other FD flags 
> > from the script.
> 
> Interesting!  I had misunderstood the complaint, which is that the fd
> leaks *from* bash *to* the program being executed (pvs in the example).
> 
> One aspect is that is the specified behavior of bash.

Given the snippet above, if it were in a script, one would assume that
passing the open FD 66 to the child process was the script author's
intent.  This is useful in a few niche cases.  A similar example that
comes to mind is DJB's tcpclient
<https://cr.yp.to/ucspi-tcp/tcpclient.html> which runs a program with
file descriptors 6 and 7 pre-opened.

The fact that pvs *complains* about this instead of just ignoring it makes
it fairly unique.  I don't know why the authors of pvs chose to do this.
Perhaps they were working around some known or suspected bug in some other
program that was commonly used as pvs's parent.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]