aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-08-30 14:16:41 -0700
committerJunio C Hamano <gitster@pobox.com>2022-08-30 14:16:41 -0700
commit78861eb58a17fc4041cb38879e194735e960dba5 (patch)
tree18bb11972630ee0956d5ef865fae5ff2bc06c0f2
parentSync with Git 2.37.3 (diff)
parenttempfile: avoid directory cleanup race (diff)
downloadgit-78861eb58a17fc4041cb38879e194735e960dba5.tar.gz
git-78861eb58a17fc4041cb38879e194735e960dba5.zip
Merge branch 'rs/tempfile-cleanup-race-fix' into jk/tempfile-active-flag-cleanup
* rs/tempfile-cleanup-race-fix: tempfile: avoid directory cleanup race
-rw-r--r--tempfile.c14
-rw-r--r--tempfile.h2
2 files changed, 7 insertions, 9 deletions
diff --git a/tempfile.c b/tempfile.c
index 2024c82691..7414c81e31 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -59,14 +59,11 @@ static VOLATILE_LIST_HEAD(tempfile_list);
static void remove_template_directory(struct tempfile *tempfile,
int in_signal_handler)
{
- if (tempfile->directorylen > 0 &&
- tempfile->directorylen < tempfile->filename.len &&
- tempfile->filename.buf[tempfile->directorylen] == '/') {
- strbuf_setlen(&tempfile->filename, tempfile->directorylen);
+ if (tempfile->directory) {
if (in_signal_handler)
- rmdir(tempfile->filename.buf);
+ rmdir(tempfile->directory);
else
- rmdir_or_warn(tempfile->filename.buf);
+ rmdir_or_warn(tempfile->directory);
}
}
@@ -115,7 +112,7 @@ static struct tempfile *new_tempfile(void)
tempfile->owner = 0;
INIT_LIST_HEAD(&tempfile->list);
strbuf_init(&tempfile->filename, 0);
- tempfile->directorylen = 0;
+ tempfile->directory = NULL;
return tempfile;
}
@@ -141,6 +138,7 @@ static void deactivate_tempfile(struct tempfile *tempfile)
{
tempfile->active = 0;
strbuf_release(&tempfile->filename);
+ free(tempfile->directory);
volatile_list_del(&tempfile->list);
free(tempfile);
}
@@ -254,7 +252,7 @@ struct tempfile *mks_tempfile_dt(const char *directory_template,
tempfile = new_tempfile();
strbuf_swap(&tempfile->filename, &sb);
- tempfile->directorylen = directorylen;
+ tempfile->directory = xmemdupz(tempfile->filename.buf, directorylen);
tempfile->fd = fd;
activate_tempfile(tempfile);
return tempfile;
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;
};
/*