diff options
author | René Scharfe <l.s.r@web.de> | 2022-08-27 01:46:29 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-08-27 20:17:46 +0300 |
commit | babe2e05592f0e8025061ffc97e387e2aa70c99b (patch) | |
tree | 8ae391e3f752bc233644839dcc365e048513c38f /tempfile.h | |
parent | 0f5bd024f21b3700ce37148d75ad7918bf9977f8 (diff) |
tempfile: avoid directory cleanup race
The temporary directory created by mks_tempfile_dt() is deleted by first
deleting the file within, then truncating the filename strbuf and
passing the resulting string to rmdir(2). When the cleanup routine is
invoked concurrently by a signal handler we can end up passing the now
truncated string to unlink(2), however, which could cause problems on
some systems.
Avoid that issue by remembering the directory name separately. This way
the paths stay unchanged. A signal handler can still race with normal
cleanup, but deleting the same files and directories twice is harmless.
Reported-by: Jeff King <peff@peff.net>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tempfile.h')
-rw-r--r-- | tempfile.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tempfile.h b/tempfile.h index d7804a214a..5b9e8743dd 100644 --- a/tempfile.h +++ b/tempfile.h @@ -82,7 +82,7 @@ struct tempfile { FILE *volatile fp; volatile pid_t owner; struct strbuf filename; - size_t directorylen; + char *directory; }; /* |