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>
This commit is contained in:
parent
074e8dcba7
commit
af1c8e8be0
@ -364,7 +364,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
archive_handle = init_handle();
|
archive_handle = init_handle();
|
||||||
archive_handle->src_fd = STDIN_FILENO;
|
/* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
|
||||||
archive_handle->seek = seek_by_read;
|
archive_handle->seek = seek_by_read;
|
||||||
archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
|
archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
|
||||||
|
|
||||||
|
@ -70,6 +70,15 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
|||||||
file_header->name = xzalloc(namesize + 1);
|
file_header->name = xzalloc(namesize + 1);
|
||||||
/* Read in filename */
|
/* Read in filename */
|
||||||
xread(archive_handle->src_fd, file_header->name, namesize);
|
xread(archive_handle->src_fd, file_header->name, namesize);
|
||||||
|
if (file_header->name[0] == '/') {
|
||||||
|
/* Testcase: echo /etc/hosts | cpio -pvd /tmp
|
||||||
|
* Without this code, it tries to unpack /etc/hosts
|
||||||
|
* into "/etc/hosts", not "etc/hosts".
|
||||||
|
*/
|
||||||
|
char *p = file_header->name;
|
||||||
|
do p++; while (*p == '/');
|
||||||
|
overlapping_strcpy(file_header->name, p);
|
||||||
|
}
|
||||||
archive_handle->offset += namesize;
|
archive_handle->offset += namesize;
|
||||||
|
|
||||||
/* Update offset amount and skip padding before file contents */
|
/* Update offset amount and skip padding before file contents */
|
||||||
|
@ -36,6 +36,7 @@ ls -ln cpio.testdir | $FILTER_LS" \
|
|||||||
"\
|
"\
|
||||||
1 blocks
|
1 blocks
|
||||||
0
|
0
|
||||||
|
total 0
|
||||||
-rw-r--r-- 2 $user $group 0 x
|
-rw-r--r-- 2 $user $group 0 x
|
||||||
-rw-r--r-- 2 $user $group 0 y
|
-rw-r--r-- 2 $user $group 0 y
|
||||||
" \
|
" \
|
||||||
@ -47,10 +48,10 @@ test x"$SKIP_KNOWN_BUGS" = x"" && {
|
|||||||
testing "cpio lists hardlinks" \
|
testing "cpio lists hardlinks" \
|
||||||
"$ECHO -ne '$hexdump' | bzcat | cpio -t 2>&1; echo \$?" \
|
"$ECHO -ne '$hexdump' | bzcat | cpio -t 2>&1; echo \$?" \
|
||||||
"\
|
"\
|
||||||
1 block
|
|
||||||
cpio.testdir
|
cpio.testdir
|
||||||
cpio.testdir/x
|
cpio.testdir/x
|
||||||
cpio.testdir/y
|
cpio.testdir/y
|
||||||
|
1 blocks
|
||||||
0
|
0
|
||||||
" \
|
" \
|
||||||
"" ""
|
"" ""
|
||||||
@ -72,6 +73,7 @@ ls -ln cpio.testdir2/cpio.testdir | $FILTER_LS" \
|
|||||||
"\
|
"\
|
||||||
2 blocks
|
2 blocks
|
||||||
0
|
0
|
||||||
|
total 8
|
||||||
-rw-r--r-- 2 $user $group 0 empty
|
-rw-r--r-- 2 $user $group 0 empty
|
||||||
-rw-r--r-- 2 $user $group 0 empty1
|
-rw-r--r-- 2 $user $group 0 empty1
|
||||||
-rw-r--r-- 2 $user $group 2 nonempty
|
-rw-r--r-- 2 $user $group 2 nonempty
|
||||||
|
Loading…
Reference in New Issue
Block a user