diff options
author | Harald van Dijk <harald@gigawatt.nl> | 2018-05-22 17:34:31 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-05-22 17:34:31 +0200 |
commit | 8c24af9dcfe0d89a660c39838eec4d20bc13efbf (patch) | |
tree | 1be6f930fb21383ba8c46a6d0491cafe3e26d687 /archival/libarchive | |
parent | a40a661d971cf75c617c83357ac0e87a45f41f4f (diff) | |
download | busybox-w32-8c24af9dcfe0d89a660c39838eec4d20bc13efbf.tar.gz busybox-w32-8c24af9dcfe0d89a660c39838eec4d20bc13efbf.tar.bz2 busybox-w32-8c24af9dcfe0d89a660c39838eec4d20bc13efbf.zip |
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/libarchive')
-rw-r--r-- | archival/libarchive/data_extract_all.c | 16 | ||||
-rw-r--r-- | archival/libarchive/get_header_ar.c | 2 | ||||
-rw-r--r-- | archival/libarchive/unsafe_symlink_target.c | 21 |
3 files changed, 19 insertions, 20 deletions
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) | |||
122 | 122 | ||
123 | /* Handle hard links separately */ | 123 | /* Handle hard links separately */ |
124 | if (hard_link) { | 124 | if (hard_link) { |
125 | res = link(hard_link, dst_name); | 125 | create_or_remember_link(&archive_handle->link_placeholders, |
126 | if (res != 0) { | 126 | hard_link, |
127 | /* shared message */ | 127 | dst_name, |
128 | bb_perror_msg("can't create %slink '%s' to '%s'", | 128 | 1); |
129 | "hard", dst_name, hard_link | ||
130 | ); | ||
131 | } | ||
132 | /* Hardlinks have no separate mode/ownership, skip chown/chmod */ | 129 | /* Hardlinks have no separate mode/ownership, skip chown/chmod */ |
133 | goto ret; | 130 | goto ret; |
134 | } | 131 | } |
@@ -195,9 +192,10 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle) | |||
195 | * | 192 | * |
196 | * Untarring bug.tar would otherwise place evil.py in '/tmp'. | 193 | * Untarring bug.tar would otherwise place evil.py in '/tmp'. |
197 | */ | 194 | */ |
198 | create_or_remember_symlink(&archive_handle->symlink_placeholders, | 195 | create_or_remember_link(&archive_handle->link_placeholders, |
199 | file_header->link_target, | 196 | file_header->link_target, |
200 | dst_name); | 197 | dst_name, |
198 | 0); | ||
201 | break; | 199 | break; |
202 | case S_IFSOCK: | 200 | case S_IFSOCK: |
203 | case S_IFBLK: | 201 | 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) | |||
126 | struct archive_handle_t *sa = archive_handle->dpkg__sub_archive; | 126 | struct archive_handle_t *sa = archive_handle->dpkg__sub_archive; |
127 | while (archive_handle->dpkg__action_data_subarchive(sa) == EXIT_SUCCESS) | 127 | while (archive_handle->dpkg__action_data_subarchive(sa) == EXIT_SUCCESS) |
128 | continue; | 128 | continue; |
129 | create_symlinks_from_list(sa->symlink_placeholders); | 129 | create_links_from_list(sa->link_placeholders); |
130 | } else | 130 | } else |
131 | #endif | 131 | #endif |
132 | archive_handle->action_data(archive_handle); | 132 | 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 @@ | |||
5 | #include "libbb.h" | 5 | #include "libbb.h" |
6 | #include "bb_archive.h" | 6 | #include "bb_archive.h" |
7 | 7 | ||
8 | void FAST_FUNC create_or_remember_symlink(llist_t **symlink_placeholders, | 8 | void FAST_FUNC create_or_remember_link(llist_t **link_placeholders, |
9 | const char *target, | 9 | const char *target, |
10 | const char *linkname) | 10 | const char *linkname, |
11 | int hard_link) | ||
11 | { | 12 | { |
12 | if (target[0] == '/' || strstr(target, "..")) { | 13 | if (hard_link || target[0] == '/' || strstr(target, "..")) { |
13 | llist_add_to(symlink_placeholders, | 14 | llist_add_to_end(link_placeholders, |
14 | xasprintf("%s%c%s", linkname, '\0', target) | 15 | xasprintf("%c%s%c%s", hard_link, linkname, '\0', target) |
15 | ); | 16 | ); |
16 | return; | 17 | return; |
17 | } | 18 | } |
@@ -23,17 +24,17 @@ void FAST_FUNC create_or_remember_symlink(llist_t **symlink_placeholders, | |||
23 | } | 24 | } |
24 | } | 25 | } |
25 | 26 | ||
26 | void FAST_FUNC create_symlinks_from_list(llist_t *list) | 27 | void FAST_FUNC create_links_from_list(llist_t *list) |
27 | { | 28 | { |
28 | while (list) { | 29 | while (list) { |
29 | char *target; | 30 | char *target; |
30 | 31 | ||
31 | target = list->data + strlen(list->data) + 1; | 32 | target = list->data + 1 + strlen(list->data + 1) + 1; |
32 | if (symlink(target, list->data)) { | 33 | if ((*list->data ? link : symlink) (target, list->data + 1)) { |
33 | /* shared message */ | 34 | /* shared message */ |
34 | bb_error_msg_and_die("can't create %slink '%s' to '%s'", | 35 | bb_error_msg_and_die("can't create %slink '%s' to '%s'", |
35 | "sym", | 36 | *list->data ? "hard" : "sym", |
36 | list->data, target | 37 | list->data + 1, target |
37 | ); | 38 | ); |
38 | } | 39 | } |
39 | list = list->link; | 40 | list = list->link; |