1 diff -uprk.orig cpio-2.6.orig/src/copyin.c cpio-2.6/src/copyin.c
2 --- cpio-2.6.orig/src/copyin.c 2005-04-26 18:01:02 +0400
3 +++ cpio-2.6/src/copyin.c 2005-04-26 22:19:07 +0400
12 @@ -1335,6 +1336,53 @@
16 +/* Return a safer suffix of FILE_NAME, or "." if it has no safer
17 + suffix. Check for fully specified file names and other atrocities. */
20 +safer_name_suffix (char const *file_name)
24 + /* Skip file system prefixes, leading file name components that contain
25 + "..", and leading slashes. */
27 + size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (file_name);
29 + for (p = file_name + prefix_len; *p;)
31 + if (p[0] == '.' && p[1] == '.' && (ISSLASH (p[2]) || !p[2]))
32 + prefix_len = p + 2 - file_name;
43 + for (p = file_name + prefix_len; ISSLASH (*p); p++)
45 + prefix_len = p - file_name;
49 + char *prefix = alloca (prefix_len + 1);
50 + memcpy (prefix, file_name, prefix_len);
51 + prefix[prefix_len] = '\0';
54 + error (0, 0, _("Removing leading `%s' from member names"), prefix);
63 /* Read the collection from standard input and create files
64 in the file system. */
66 @@ -1448,18 +1496,11 @@ process_copy_in ()
68 /* Do we have to ignore absolute paths, and if so, does the filename
69 have an absolute path? */
70 - if (no_abs_paths_flag && file_hdr.c_name && file_hdr.c_name [0] == '/')
71 + if (!abs_paths_flag && file_hdr.c_name && file_hdr.c_name [0])
74 + char *p = safer_name_suffix (file_hdr.c_name);
76 - p = file_hdr.c_name;
81 - strcpy (file_hdr.c_name, ".");
84 + if (p != file_hdr.c_name)
86 /* Debian hack: file_hrd.c_name is sometimes set to
87 point to static memory by code in tar.c. This
88 diff -uprk.orig cpio-2.6.orig/src/extern.h cpio-2.6/src/extern.h
89 --- cpio-2.6.orig/src/extern.h 2005-04-26 18:01:02 +0400
90 +++ cpio-2.6/src/extern.h 2005-04-26 22:17:49 +0400
92 extern int sparse_flag;
93 extern int quiet_flag;
94 extern int only_verify_crc_flag;
95 -extern int no_abs_paths_flag;
96 +extern int abs_paths_flag;
97 extern unsigned int warn_option;
99 /* Values for warn_option */
100 diff -uprk.orig cpio-2.6.orig/src/global.c cpio-2.6/src/global.c
101 --- cpio-2.6.orig/src/global.c 2004-09-08 14:23:44 +0400
102 +++ cpio-2.6/src/global.c 2005-04-26 22:19:27 +0400
104 int only_verify_crc_flag = false;
106 /* If true, don't use any absolute paths, prefix them by `./'. */
107 -int no_abs_paths_flag = false;
108 +int abs_paths_flag = false;
111 /* If true, print debugging information. */
112 diff -uprk.orig cpio-2.6.orig/src/main.c cpio-2.6/src/main.c
113 --- cpio-2.6.orig/src/main.c 2005-04-26 18:01:02 +0400
114 +++ cpio-2.6/src/main.c 2005-04-26 22:24:55 +0400
118 NO_ABSOLUTE_FILENAMES_OPTION=256,
119 + ABSOLUTE_FILENAMES_OPTION,
120 NO_PRESERVE_OWNER_OPTION,
121 ONLY_VERIFY_CRC_OPTION,
122 RENAME_BATCH_FILE_OPTION,
123 @@ -134,6 +135,8 @@ static struct argp_option options[] = {
124 N_("In copy-in mode, read additional patterns specifying filenames to extract or list from FILE"), 210},
125 {"no-absolute-filenames", NO_ABSOLUTE_FILENAMES_OPTION, 0, 0,
126 N_("Create all files relative to the current directory"), 210},
127 + {"absolute-filenames", ABSOLUTE_FILENAMES_OPTION, 0, 0,
128 + N_("do not strip leading file name components that contain \"..\" and leading slashes from file names"), 210},
129 {"only-verify-crc", ONLY_VERIFY_CRC_OPTION, 0, 0,
130 N_("When reading a CRC format archive in copy-in mode, only verify the CRC's of each file in the archive, don't actually extract the files"), 210},
131 {"rename", 'r', 0, 0,
132 @@ -393,7 +396,11 @@ crc newc odc bin ustar tar (all-caps als
135 case NO_ABSOLUTE_FILENAMES_OPTION: /* --no-absolute-filenames */
136 - no_abs_paths_flag = true;
137 + abs_paths_flag = false;
140 + case ABSOLUTE_FILENAMES_OPTION: /* --absolute-filenames */
141 + abs_paths_flag = true;
144 case NO_PRESERVE_OWNER_OPTION: /* --no-preserve-owner */
145 @@ -631,7 +638,7 @@ process_args (int argc, char *argv[])
146 _("--append is used but no archive file name is given (use -F or -O options")));
148 CHECK_USAGE(rename_batch_file, "--rename-batch-file", "--create");
149 - CHECK_USAGE(no_abs_paths_flag, "--no-absolute-pathnames", "--create");
150 + CHECK_USAGE(abs_paths_flag, "--absolute-pathnames", "--create");
151 CHECK_USAGE(input_archive_name, "-I", "--create");
152 if (archive_name && output_archive_name)
153 USAGE_ERROR ((0, 0, _("Both -O and -F are used in copy-out mode")));
154 @@ -658,7 +665,7 @@ process_args (int argc, char *argv[])
155 CHECK_USAGE(rename_flag, "--rename", "--pass-through");
156 CHECK_USAGE(append_flag, "--append", "--pass-through");
157 CHECK_USAGE(rename_batch_file, "--rename-batch-file", "--pass-through");
158 - CHECK_USAGE(no_abs_paths_flag, "--no-absolute-pathnames",
159 + CHECK_USAGE(abs_paths_flag, "--absolute-pathnames",
161 CHECK_USAGE(to_stdout_option, "--to-stdout", "--pass-through");