2022-10-31 12:54:41 +01:00
|
|
|
From 79d1ac38c19faad64f0e993180bf1ad27f217072 Mon Sep 17 00:00:00 2001
|
|
|
|
From: James Abbatiello <abbeyj@gmail.com>
|
|
|
|
Date: Fri, 10 Jun 2022 18:25:13 -0700
|
|
|
|
Subject: tar: fix race condition
|
2022-08-20 08:22:41 +02:00
|
|
|
|
2022-10-31 12:54:41 +01:00
|
|
|
Problem reported in:
|
2022-08-20 08:22:41 +02:00
|
|
|
https://lists.gnu.org/r/bug-tar/2022-03/msg00000.html
|
2022-10-31 12:54:41 +01:00
|
|
|
* src/extract.c (make_directories): Retry the file creation as
|
|
|
|
long as the directory exists, regardless of whether tar itself
|
|
|
|
created the directory.
|
|
|
|
Copyright-paperwork-exempt: Yes
|
2022-08-20 08:22:41 +02:00
|
|
|
---
|
2022-10-31 12:54:41 +01:00
|
|
|
src/extract.c | 16 ++++++++--------
|
|
|
|
1 file changed, 8 insertions(+), 8 deletions(-)
|
2022-08-20 08:22:41 +02:00
|
|
|
|
2022-10-31 12:54:41 +01:00
|
|
|
diff --git a/src/extract.c b/src/extract.c
|
|
|
|
index 0753dec..fda4617 100644
|
|
|
|
--- a/src/extract.c
|
|
|
|
+++ b/src/extract.c
|
|
|
|
@@ -638,10 +638,9 @@ fixup_delayed_set_stat (char const *src, char const *dst)
|
|
|
|
|
|
|
|
/* After a file/link/directory creation has failed due to ENOENT,
|
2022-08-20 08:22:41 +02:00
|
|
|
create all required directories. Return zero if all the required
|
2022-10-31 12:54:41 +01:00
|
|
|
- directories were created, nonzero (issuing a diagnostic) otherwise.
|
2022-08-20 08:22:41 +02:00
|
|
|
- Set *INTERDIR_MADE if at least one directory was created. */
|
2022-10-31 12:54:41 +01:00
|
|
|
+ directories were created, nonzero (issuing a diagnostic) otherwise. */
|
2022-08-20 08:22:41 +02:00
|
|
|
static int
|
|
|
|
-make_directories (char *file_name, bool *interdir_made)
|
|
|
|
+make_directories (char *file_name)
|
|
|
|
{
|
|
|
|
char *cursor0 = file_name + FILE_SYSTEM_PREFIX_LEN (file_name);
|
|
|
|
char *cursor; /* points into the file name */
|
2022-10-31 12:54:41 +01:00
|
|
|
@@ -685,7 +684,6 @@ make_directories (char *file_name, bool *interdir_made)
|
2022-08-20 08:22:41 +02:00
|
|
|
desired_mode, AT_SYMLINK_NOFOLLOW);
|
|
|
|
|
|
|
|
print_for_mkdir (file_name, cursor - file_name, desired_mode);
|
|
|
|
- *interdir_made = true;
|
2022-10-31 12:54:41 +01:00
|
|
|
parent_end = NULL;
|
2022-08-20 08:22:41 +02:00
|
|
|
}
|
2022-10-31 12:54:41 +01:00
|
|
|
else
|
|
|
|
@@ -841,8 +839,11 @@ maybe_recoverable (char *file_name, bool regular, bool *interdir_made)
|
2022-08-20 08:22:41 +02:00
|
|
|
|
|
|
|
case ENOENT:
|
|
|
|
/* Attempt creating missing intermediate directories. */
|
2022-10-31 12:54:41 +01:00
|
|
|
- if (make_directories (file_name, interdir_made) == 0)
|
2022-08-20 08:22:41 +02:00
|
|
|
- return RECOVER_OK;
|
|
|
|
+ if (make_directories (file_name) == 0)
|
2022-10-31 12:54:41 +01:00
|
|
|
+ {
|
|
|
|
+ *interdir_made = true;
|
|
|
|
+ return RECOVER_OK;
|
|
|
|
+ }
|
2022-08-20 08:22:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-10-31 12:54:41 +01:00
|
|
|
@@ -1944,12 +1945,11 @@ rename_directory (char *src, char *dst)
|
2022-08-20 08:22:41 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int e = errno;
|
|
|
|
- bool interdir_made;
|
|
|
|
|
|
|
|
switch (e)
|
|
|
|
{
|
|
|
|
case ENOENT:
|
|
|
|
- if (make_directories (dst, &interdir_made) == 0)
|
|
|
|
+ if (make_directories (dst) == 0)
|
|
|
|
{
|
|
|
|
if (renameat (chdir_fd, src, chdir_fd, dst) == 0)
|
|
|
|
return true;
|
2022-10-31 12:54:41 +01:00
|
|
|
--
|
|
|
|
cgit v1.1
|
|
|
|
|