aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
Diffstat (limited to 'archival')
-rw-r--r--archival/libarchive/get_header_tar.c51
-rw-r--r--archival/tar.c13
2 files changed, 32 insertions, 32 deletions
diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c
index 6a1532c86..f73cd338e 100644
--- a/archival/libarchive/get_header_tar.c
+++ b/archival/libarchive/get_header_tar.c
@@ -18,6 +18,35 @@ typedef uint32_t aliased_uint32_t FIX_ALIASING;
typedef off_t aliased_off_t FIX_ALIASING;
+const char* FAST_FUNC strip_unsafe_prefix(const char *str)
+{
+ const char *cp = str;
+ while (1) {
+ char *cp2;
+ if (*cp == '/') {
+ cp++;
+ continue;
+ }
+ if (strncmp(cp, "/../"+1, 3) == 0) {
+ cp += 3;
+ continue;
+ }
+ cp2 = strstr(cp, "/../");
+ if (!cp2)
+ break;
+ cp = cp2 + 4;
+ }
+ if (cp != str) {
+ static smallint warned = 0;
+ if (!warned) {
+ warned = 1;
+ bb_error_msg("removing leading '%.*s' from member names",
+ (int)(cp - str), str);
+ }
+ }
+ return cp;
+}
+
/* NB: _DESTROYS_ str[len] character! */
static unsigned long long getOctal(char *str, int len)
{
@@ -424,27 +453,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
#endif
/* Everything up to and including last ".." component is stripped */
- cp = file_header->name;
- while (1) {
- char *cp2;
- if (strncmp(cp, "/../"+1, 3) == 0) {
- cp += 3;
- continue;
- }
- cp2 = strstr(cp, "/../");
- if (cp2) {
- cp = cp2 + 4;
- continue;
- }
- break;
- }
- if (cp != file_header->name) {
- if (!(archive_handle->ah_flags & ARCHIVE_TAR__TRUNC_WARNED)) {
- archive_handle->ah_flags |= ARCHIVE_TAR__TRUNC_WARNED;
- bb_error_msg("removing leading '%.*s'", (int)(cp - file_header->name), file_header->name);
- }
- overlapping_strcpy(file_header->name, cp);
- }
+ overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name));
/* Strip trailing '/' in directories */
/* Must be done after mode is set as '/' is used to check if it's a directory */
diff --git a/archival/tar.c b/archival/tar.c
index 1e3cecf44..d43c8dee3 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -397,17 +397,8 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
DBG("writeFileToTarball('%s')", fileName);
- /* Strip leading '/' (must be before memorizing hardlink's name) */
- header_name = fileName;
- while (header_name[0] == '/') {
- static smallint warned;
-
- if (!warned) {
- bb_error_msg("removing leading '/' from member names");
- warned = 1;
- }
- header_name++;
- }
+ /* Strip leading '/' and such (must be before memorizing hardlink's name) */
+ header_name = strip_unsafe_prefix(fileName);
if (header_name[0] == '\0')
return TRUE;