diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-05 04:43:21 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-05 04:43:21 +0100 |
commit | af1c8e8be070f2121d5d977c5ed7a7f60c03a6dc (patch) | |
tree | 7f0bc3627ab6b07baf8d8b835e5d47f5c9cb34c5 | |
parent | 074e8dcba76ac2a313d6a14ca2289e648f926b25 (diff) | |
download | busybox-w32-af1c8e8be070f2121d5d977c5ed7a7f60c03a6dc.tar.gz busybox-w32-af1c8e8be070f2121d5d977c5ed7a7f60c03a6dc.tar.bz2 busybox-w32-af1c8e8be070f2121d5d977c5ed7a7f60c03a6dc.zip |
cpio: fix unpacking of names with leading slashes
function old new delta
get_header_cpio 968 990 +22
cpio_main 533 526 -7
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/cpio.c | 2 | ||||
-rw-r--r-- | archival/libunarchive/get_header_cpio.c | 9 | ||||
-rwxr-xr-x | testsuite/cpio.tests | 4 |
3 files changed, 13 insertions, 2 deletions
diff --git a/archival/cpio.c b/archival/cpio.c index 5c16678e4..067d6e88d 100644 --- a/archival/cpio.c +++ b/archival/cpio.c | |||
@@ -364,7 +364,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv) | |||
364 | #endif | 364 | #endif |
365 | 365 | ||
366 | archive_handle = init_handle(); | 366 | archive_handle = init_handle(); |
367 | archive_handle->src_fd = STDIN_FILENO; | 367 | /* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */ |
368 | archive_handle->seek = seek_by_read; | 368 | archive_handle->seek = seek_by_read; |
369 | archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER; | 369 | archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER; |
370 | 370 | ||
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c index 302f12233..52854dff9 100644 --- a/archival/libunarchive/get_header_cpio.c +++ b/archival/libunarchive/get_header_cpio.c | |||
@@ -70,6 +70,15 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) | |||
70 | file_header->name = xzalloc(namesize + 1); | 70 | file_header->name = xzalloc(namesize + 1); |
71 | /* Read in filename */ | 71 | /* Read in filename */ |
72 | xread(archive_handle->src_fd, file_header->name, namesize); | 72 | xread(archive_handle->src_fd, file_header->name, namesize); |
73 | if (file_header->name[0] == '/') { | ||
74 | /* Testcase: echo /etc/hosts | cpio -pvd /tmp | ||
75 | * Without this code, it tries to unpack /etc/hosts | ||
76 | * into "/etc/hosts", not "etc/hosts". | ||
77 | */ | ||
78 | char *p = file_header->name; | ||
79 | do p++; while (*p == '/'); | ||
80 | overlapping_strcpy(file_header->name, p); | ||
81 | } | ||
73 | archive_handle->offset += namesize; | 82 | archive_handle->offset += namesize; |
74 | 83 | ||
75 | /* Update offset amount and skip padding before file contents */ | 84 | /* Update offset amount and skip padding before file contents */ |
diff --git a/testsuite/cpio.tests b/testsuite/cpio.tests index f21ba18d1..56f1885ac 100755 --- a/testsuite/cpio.tests +++ b/testsuite/cpio.tests | |||
@@ -36,6 +36,7 @@ ls -ln cpio.testdir | $FILTER_LS" \ | |||
36 | "\ | 36 | "\ |
37 | 1 blocks | 37 | 1 blocks |
38 | 0 | 38 | 0 |
39 | total 0 | ||
39 | -rw-r--r-- 2 $user $group 0 x | 40 | -rw-r--r-- 2 $user $group 0 x |
40 | -rw-r--r-- 2 $user $group 0 y | 41 | -rw-r--r-- 2 $user $group 0 y |
41 | " \ | 42 | " \ |
@@ -47,10 +48,10 @@ test x"$SKIP_KNOWN_BUGS" = x"" && { | |||
47 | testing "cpio lists hardlinks" \ | 48 | testing "cpio lists hardlinks" \ |
48 | "$ECHO -ne '$hexdump' | bzcat | cpio -t 2>&1; echo \$?" \ | 49 | "$ECHO -ne '$hexdump' | bzcat | cpio -t 2>&1; echo \$?" \ |
49 | "\ | 50 | "\ |
50 | 1 block | ||
51 | cpio.testdir | 51 | cpio.testdir |
52 | cpio.testdir/x | 52 | cpio.testdir/x |
53 | cpio.testdir/y | 53 | cpio.testdir/y |
54 | 1 blocks | ||
54 | 0 | 55 | 0 |
55 | " \ | 56 | " \ |
56 | "" "" | 57 | "" "" |
@@ -72,6 +73,7 @@ ls -ln cpio.testdir2/cpio.testdir | $FILTER_LS" \ | |||
72 | "\ | 73 | "\ |
73 | 2 blocks | 74 | 2 blocks |
74 | 0 | 75 | 0 |
76 | total 8 | ||
75 | -rw-r--r-- 2 $user $group 0 empty | 77 | -rw-r--r-- 2 $user $group 0 empty |
76 | -rw-r--r-- 2 $user $group 0 empty1 | 78 | -rw-r--r-- 2 $user $group 0 empty1 |
77 | -rw-r--r-- 2 $user $group 2 nonempty | 79 | -rw-r--r-- 2 $user $group 2 nonempty |