aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorHarald van Dijk <harald@gigawatt.nl>2018-05-22 17:34:31 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-05-22 17:34:31 +0200
commit8c24af9dcfe0d89a660c39838eec4d20bc13efbf (patch)
tree1be6f930fb21383ba8c46a6d0491cafe3e26d687 /archival
parenta40a661d971cf75c617c83357ac0e87a45f41f4f (diff)
downloadbusybox-8c24af9dcfe0d89a660c39838eec4d20bc13efbf.tar.gz
tar: fix interaction of delayed symlink and hardlink creation
function old new delta create_or_remember_link - 106 +106 create_links_from_list - 93 +93 find_applet_by_name 124 128 +4 unzip_main 2724 2726 +2 data_extract_all 891 873 -18 create_symlinks_from_list 64 - -64 create_or_remember_symlink 94 - -94 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 2/1 up/down: 205/-176) Total: 29 bytes Signed-off-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'archival')
-rw-r--r--archival/cpio.c2
-rw-r--r--archival/libarchive/data_extract_all.c16
-rw-r--r--archival/libarchive/get_header_ar.c2
-rw-r--r--archival/libarchive/unsafe_symlink_target.c21
-rw-r--r--archival/tar.c2
-rw-r--r--archival/unzip.c7
6 files changed, 25 insertions, 25 deletions
diff --git a/archival/cpio.c b/archival/cpio.c
index 308ec1b25..221667112 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -508,7 +508,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
- create_symlinks_from_list(archive_handle->symlink_placeholders);
+ create_links_from_list(archive_handle->link_placeholders);
if (archive_handle->cpio__blocks != (off_t)-1
&& !(opt & OPT_QUIET)
diff --git a/archival/libarchive/data_extract_all.c b/archival/libarchive/data_extract_all.c
index 8fa69ffaf..4c95db4a6 100644
--- a/archival/libarchive/data_extract_all.c
+++ b/archival/libarchive/data_extract_all.c
@@ -122,13 +122,10 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
/* Handle hard links separately */
if (hard_link) {
- res = link(hard_link, dst_name);
- if (res != 0) {
- /* shared message */
- bb_perror_msg("can't create %slink '%s' to '%s'",
- "hard", dst_name, hard_link
- );
- }
+ create_or_remember_link(&archive_handle->link_placeholders,
+ hard_link,
+ dst_name,
+ 1);
/* Hardlinks have no separate mode/ownership, skip chown/chmod */
goto ret;
}
@@ -195,9 +192,10 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
*
* Untarring bug.tar would otherwise place evil.py in '/tmp'.
*/
- create_or_remember_symlink(&archive_handle->symlink_placeholders,
+ create_or_remember_link(&archive_handle->link_placeholders,
file_header->link_target,
- dst_name);
+ dst_name,
+ 0);
break;
case S_IFSOCK:
case S_IFBLK:
diff --git a/archival/libarchive/get_header_ar.c b/archival/libarchive/get_header_ar.c
index adcde46d5..7ce9c615c 100644
--- a/archival/libarchive/get_header_ar.c
+++ b/archival/libarchive/get_header_ar.c
@@ -126,7 +126,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
struct archive_handle_t *sa = archive_handle->dpkg__sub_archive;
while (archive_handle->dpkg__action_data_subarchive(sa) == EXIT_SUCCESS)
continue;
- create_symlinks_from_list(sa->symlink_placeholders);
+ create_links_from_list(sa->link_placeholders);
} else
#endif
archive_handle->action_data(archive_handle);
diff --git a/archival/libarchive/unsafe_symlink_target.c b/archival/libarchive/unsafe_symlink_target.c
index 8dcafeaa1..f8dc8033d 100644
--- a/archival/libarchive/unsafe_symlink_target.c
+++ b/archival/libarchive/unsafe_symlink_target.c
@@ -5,13 +5,14 @@
#include "libbb.h"
#include "bb_archive.h"
-void FAST_FUNC create_or_remember_symlink(llist_t **symlink_placeholders,
+void FAST_FUNC create_or_remember_link(llist_t **link_placeholders,
const char *target,
- const char *linkname)
+ const char *linkname,
+ int hard_link)
{
- if (target[0] == '/' || strstr(target, "..")) {
- llist_add_to(symlink_placeholders,
- xasprintf("%s%c%s", linkname, '\0', target)
+ if (hard_link || target[0] == '/' || strstr(target, "..")) {
+ llist_add_to_end(link_placeholders,
+ xasprintf("%c%s%c%s", hard_link, linkname, '\0', target)
);
return;
}
@@ -23,17 +24,17 @@ void FAST_FUNC create_or_remember_symlink(llist_t **symlink_placeholders,
}
}
-void FAST_FUNC create_symlinks_from_list(llist_t *list)
+void FAST_FUNC create_links_from_list(llist_t *list)
{
while (list) {
char *target;
- target = list->data + strlen(list->data) + 1;
- if (symlink(target, list->data)) {
+ target = list->data + 1 + strlen(list->data + 1) + 1;
+ if ((*list->data ? link : symlink) (target, list->data + 1)) {
/* shared message */
bb_error_msg_and_die("can't create %slink '%s' to '%s'",
- "sym",
- list->data, target
+ *list->data ? "hard" : "sym",
+ list->data + 1, target
);
}
list = list->link;
diff --git a/archival/tar.c b/archival/tar.c
index a8b888fa9..ae1ccc756 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -1244,7 +1244,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
while (get_header_tar(tar_handle) == EXIT_SUCCESS)
bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */
- create_symlinks_from_list(tar_handle->symlink_placeholders);
+ create_links_from_list(tar_handle->link_placeholders);
/* Check that every file that should have been extracted was */
while (tar_handle->accept) {
diff --git a/archival/unzip.c b/archival/unzip.c
index 0d00d8dc9..96b7ab69b 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -372,9 +372,10 @@ static void unzip_extract_symlink(llist_t **symlink_placeholders,
target[xstate.mem_output_size] = '\0';
#endif
}
- create_or_remember_symlink(symlink_placeholders,
+ create_or_remember_link(symlink_placeholders,
target,
- dst_fn);
+ dst_fn,
+ 0);
free(target);
}
#endif
@@ -990,7 +991,7 @@ int unzip_main(int argc, char **argv)
}
#if ENABLE_FEATURE_UNZIP_CDF
- create_symlinks_from_list(symlink_placeholders);
+ create_links_from_list(symlink_placeholders);
#endif
if ((opts & OPT_l) && quiet <= 1) {