[patch] temporary file handling
Vasiliy Kulikov
segoon@cvs.openwall.com
Sun Oct 10 09:43:00 GMT 2010
Hi,
This patch fixes some temporary file handling issues:
* mktemp() returns an empty string on error, not NULL. The code
wrongly checked for the latter, but not for the former. This is now
corrected.
* make_tempname() and make_tempdir() didn't free the pointer returned
by template_in_dir() if an error occurred in a subsequent call, such
as to mkstemp() or open(). This might have made no difference since
binutils programs would typically call fatal() if make_temp*() fails,
however it makes more of a difference along with the change below:
* make_tempname() and make_tempdir() on systems without mkstemp()
and mkdtemp(), respectively, would abort immediately if the filename
is taken (by another process) between the calls to mktemp() and
open()/mkdir(). This patch improves the code to emulate mkstemp()
and mkdtemp() more closely by retrying the mktemp() and open()/mkdir()
in a loop (much like what mkstemp() and mkdtemp() typically do).
* choose_temp_base() is not a safe API since a filename made from a
* unique
filename with a suffix appended is not guaranteed unique anymore, and
since the filename was not reserved anyway. The patch replaces the uses
of choose_temp_base() with those of make_temp_file().
* tmpnam() is a racy API. Libiberty's implementation is buggy even
without the race: it checks file existence with fopen(file, "r").
If file is accessible only for write, then fopen() fails and tmpnam()
returns the name of an already existing file. tic54x_mlib() from
tc-tic54x.c called fopen(name, "w") with the name returned from tmpnam().
So a file with no read permissions could be overwritten, including over a
(sym)link. The patch corrects this by using make_temp_file() instead.
The tempbase field from struct pex_obj was needed only for
choose_temp_base(), so I've deleted it. pexecute() and some functions
don't need the tempbase argument anymore. However, in this patch I've
only commented out some code to ignore tempbase. You might want to fix
this in a cleaner but more invasive manner.
I've tested the patch by rebuilding the Openwall GNU/*/Linux userland with
the patched binutils in place (twice on each of i686 and x86_64, with the
second rebuild using development/build tools built the first time).
This patch was originally created for H. J. Lu's version of binutils,
but it looks OK for GNU's version.
Also you can find this patch (or possible revisions of it) here:
http://cvsweb.openwall.com/cgi/cvsweb.cgi/Owl/packages/binutils/
Thanks,
--
Vasiliy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: binutils-2.20.51.0.11-owl-tmp.diff
Type: text/x-diff
Size: 11068 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20101010/64621080/attachment.bin>
More information about the Binutils
mailing list