diff options
author | Ron Yorston <rmy@pobox.com> | 2022-09-27 08:43:26 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2022-09-27 11:18:29 +0100 |
commit | a55cf07365ec2ff51749a77e09ae9edac79a99fe (patch) | |
tree | 145ab6d27987d063cbdc72b93152a141c1bd0b49 | |
parent | 1b3002fb63f83498d210cfb1cc189313df0eb8c5 (diff) | |
download | busybox-w32-a55cf07365ec2ff51749a77e09ae9edac79a99fe.tar.gz busybox-w32-a55cf07365ec2ff51749a77e09ae9edac79a99fe.tar.bz2 busybox-w32-a55cf07365ec2ff51749a77e09ae9edac79a99fe.zip |
libarchive: alter handling of failure to create symlinks
Unlike GNU tar upstream BusyBox tar treats all errors as fatal.
Failure to create a symlink on Windows is very likely due to a
lack of the required privilege. busybox-w32 therefore treats this
case as a non-fatal error and, as far as possible, continues
extracting files.
However:
- The inconsistency of this behaviour caused some confusion.
- busybox-w32 tar didn't return an error status when a non-fatal
error was encountered, unlike GNU tar.
Change the implementation so extraction continues when symlink
creation fails but the error report is deferred until all of the
archive has been processed. Only one error is reported and it's
treated as fatal.
Saves 48-64 bytes.
(GitHub issue #265)
-rw-r--r-- | archival/libarchive/unsafe_symlink_target.c | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/archival/libarchive/unsafe_symlink_target.c b/archival/libarchive/unsafe_symlink_target.c index 8e4cd4380..d9100f30f 100644 --- a/archival/libarchive/unsafe_symlink_target.c +++ b/archival/libarchive/unsafe_symlink_target.c | |||
@@ -5,29 +5,31 @@ | |||
5 | #include "libbb.h" | 5 | #include "libbb.h" |
6 | #include "bb_archive.h" | 6 | #include "bb_archive.h" |
7 | 7 | ||
8 | /* symlink may not be available for WIN32, just issue a warning */ | ||
9 | #if ENABLE_PLATFORM_MINGW32 | ||
10 | # undef bb_perror_msg_and_die | ||
11 | # define bb_perror_msg_and_die(...) bb_perror_msg(__VA_ARGS__) | ||
12 | #endif | ||
13 | |||
14 | void FAST_FUNC create_or_remember_link(llist_t **link_placeholders, | 8 | void FAST_FUNC create_or_remember_link(llist_t **link_placeholders, |
15 | const char *target, | 9 | const char *target, |
16 | const char *linkname, | 10 | const char *linkname, |
17 | int hard_link) | 11 | int hard_link) |
18 | { | 12 | { |
13 | #if ENABLE_PLATFORM_MINGW32 | ||
14 | /* defer reporting error if symlink(2) fails on Windows */ | ||
15 | if (hard_link || target[0] == '/' || strstr(target, "..") || | ||
16 | symlink(target, linkname) != 0) { | ||
17 | #else | ||
19 | if (hard_link || target[0] == '/' || strstr(target, "..")) { | 18 | if (hard_link || target[0] == '/' || strstr(target, "..")) { |
19 | #endif | ||
20 | llist_add_to_end(link_placeholders, | 20 | llist_add_to_end(link_placeholders, |
21 | xasprintf("%c%s%c%s", hard_link, linkname, '\0', target) | 21 | xasprintf("%c%s%c%s", hard_link, linkname, '\0', target) |
22 | ); | 22 | ); |
23 | return; | 23 | return; |
24 | } | 24 | } |
25 | #if !ENABLE_PLATFORM_MINGW32 | ||
25 | if (symlink(target, linkname) != 0) { | 26 | if (symlink(target, linkname) != 0) { |
26 | /* shared message */ | 27 | /* shared message */ |
27 | bb_perror_msg_and_die("can't create %slink '%s' to '%s'", | 28 | bb_perror_msg_and_die("can't create %slink '%s' to '%s'", |
28 | "sym", linkname, target | 29 | "sym", linkname, target |
29 | ); | 30 | ); |
30 | } | 31 | } |
32 | #endif | ||
31 | } | 33 | } |
32 | 34 | ||
33 | void FAST_FUNC create_links_from_list(llist_t *list) | 35 | void FAST_FUNC create_links_from_list(llist_t *list) |
@@ -37,24 +39,11 @@ void FAST_FUNC create_links_from_list(llist_t *list) | |||
37 | 39 | ||
38 | target = list->data + 1 + strlen(list->data + 1) + 1; | 40 | target = list->data + 1 + strlen(list->data + 1) + 1; |
39 | if ((*list->data ? link : symlink) (target, list->data + 1)) { | 41 | if ((*list->data ? link : symlink) (target, list->data + 1)) { |
40 | #if !ENABLE_PLATFORM_MINGW32 | ||
41 | /* shared message */ | 42 | /* shared message */ |
42 | bb_error_msg_and_die("can't create %slink '%s' to '%s'", | 43 | bb_error_msg_and_die("can't create %slink '%s' to '%s'", |
43 | *list->data ? "hard" : "sym", | 44 | *list->data ? "hard" : "sym", |
44 | list->data + 1, target | 45 | list->data + 1, target |
45 | ); | 46 | ); |
46 | #else | ||
47 | if (!*list->data) | ||
48 | bb_error_msg("can't create %slink '%s' to '%s'", | ||
49 | "sym", | ||
50 | list->data + 1, target | ||
51 | ); | ||
52 | else | ||
53 | bb_error_msg_and_die("can't create %slink '%s' to '%s'", | ||
54 | "hard", | ||
55 | list->data + 1, target | ||
56 | ); | ||
57 | #endif | ||
58 | } | 47 | } |
59 | list = list->link; | 48 | list = list->link; |
60 | } | 49 | } |