[Top][All Lists]

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

Re: Use of `mktemp' is dangerous, better use `mkstemp'...

From: Ángel
Subject: Re: Use of `mktemp' is dangerous, better use `mkstemp'...
Date: Fri, 15 Jan 2021 22:00:29 +0100

On 2021-01-15 at 10:00 -0500, Chet Ramey wrote:
> On 1/14/21 11:45 PM, Jeffrey Walton wrote:
> > Hi Everyone,
> > 
> > I'm building Bash 5.1 from sources. This may be of interest:
> > 
> > /usr/bin/ld: ./lib/sh/libsh.a(tmpfile.o): in function
> > `sh_mktmpname':
> > /home/jwalton/Build-Scripts/bash-5.1/lib/sh/tmpfile.c:160: warning:
> > the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
> It's a spurious warning.

mktemp() would only end up being used (with all its issues) if the OS
doesn't provide a DEV FD or there's no mkdtemp(). In other (safe)
Operating Systems, it would be possible to avoid the warning by
building a slightly different libsh.a in such case.

I have made a quick patch (see attachment) and it does work.
My system would normally report that warning. My compiler is smart
enough to ellide mktemp with this change. bash tests pass after the
change, both with dev-fs and disabling it (with only run-procsub
failing, but that's expected).

Best regards

Attachment: skip_mktemp.patch
Description: Text Data

reply via email to

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