"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 2 | /* Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Glenn L McGrath | 6aa5223 | 2004-02-17 11:55:06 +0000 | [diff] [blame] | 3 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 4 | * FIXME: |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 5 | * In privileged mode if uname and gname map to a uid and gid then use the |
Glenn L McGrath | c9f1fce | 2004-02-20 02:25:18 +0000 | [diff] [blame] | 6 | * mapped value instead of the uid/gid values in tar header |
Glenn L McGrath | b0e163a | 2004-02-19 08:48:30 +0000 | [diff] [blame] | 7 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 8 | * References: |
Glenn L McGrath | b0e163a | 2004-02-19 08:48:30 +0000 | [diff] [blame] | 9 | * GNU tar and star man pages, |
| 10 | * Opengroup's ustar interchange format, |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 11 | * http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 12 | */ |
| 13 | |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 14 | #include "libbb.h" |
Denys Vlasenko | 833d4e7 | 2010-11-03 02:38:31 +0100 | [diff] [blame] | 15 | #include "archive.h" |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 16 | |
Denys Vlasenko | 98a4c7c | 2010-02-04 15:00:15 +0100 | [diff] [blame] | 17 | typedef uint32_t aliased_uint32_t FIX_ALIASING; |
| 18 | typedef off_t aliased_off_t FIX_ALIASING; |
| 19 | |
| 20 | |
Denys Vlasenko | b80acf5 | 2011-03-02 01:21:02 +0100 | [diff] [blame] | 21 | const char* FAST_FUNC strip_unsafe_prefix(const char *str) |
| 22 | { |
| 23 | const char *cp = str; |
| 24 | while (1) { |
| 25 | char *cp2; |
| 26 | if (*cp == '/') { |
| 27 | cp++; |
| 28 | continue; |
| 29 | } |
| 30 | if (strncmp(cp, "/../"+1, 3) == 0) { |
| 31 | cp += 3; |
| 32 | continue; |
| 33 | } |
| 34 | cp2 = strstr(cp, "/../"); |
| 35 | if (!cp2) |
| 36 | break; |
| 37 | cp = cp2 + 4; |
| 38 | } |
| 39 | if (cp != str) { |
| 40 | static smallint warned = 0; |
| 41 | if (!warned) { |
| 42 | warned = 1; |
| 43 | bb_error_msg("removing leading '%.*s' from member names", |
| 44 | (int)(cp - str), str); |
| 45 | } |
| 46 | } |
| 47 | return cp; |
| 48 | } |
| 49 | |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 50 | /* NB: _DESTROYS_ str[len] character! */ |
| 51 | static unsigned long long getOctal(char *str, int len) |
| 52 | { |
| 53 | unsigned long long v; |
Denys Vlasenko | 7b48eb4 | 2010-05-06 20:08:14 +0200 | [diff] [blame] | 54 | char *end; |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 55 | /* NB: leading spaces are allowed. Using strtoull to handle that. |
Denys Vlasenko | 8d33817 | 2009-09-23 17:16:37 +0200 | [diff] [blame] | 56 | * The downside is that we accept e.g. "-123" too :( |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 57 | */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 58 | str[len] = '\0'; |
Denys Vlasenko | 7b48eb4 | 2010-05-06 20:08:14 +0200 | [diff] [blame] | 59 | v = strtoull(str, &end, 8); |
Denys Vlasenko | 8d33817 | 2009-09-23 17:16:37 +0200 | [diff] [blame] | 60 | /* std: "Each numeric field is terminated by one or more |
| 61 | * <space> or NUL characters". We must support ' '! */ |
Denys Vlasenko | 7b48eb4 | 2010-05-06 20:08:14 +0200 | [diff] [blame] | 62 | if (*end != '\0' && *end != ' ') { |
| 63 | int8_t first = str[0]; |
| 64 | if (!(first & 0x80)) |
| 65 | bb_error_msg_and_die("corrupted octal value in tar header"); |
| 66 | /* |
| 67 | * GNU tar uses "base-256 encoding" for very large numbers. |
| 68 | * Encoding is binary, with highest bit always set as a marker |
| 69 | * and sign in next-highest bit: |
| 70 | * 80 00 .. 00 - zero |
| 71 | * bf ff .. ff - largest positive number |
| 72 | * ff ff .. ff - minus 1 |
| 73 | * c0 00 .. 00 - smallest negative number |
| 74 | * |
| 75 | * Example of tar file with 8914993153 (0x213600001) byte file. |
| 76 | * Field starts at offset 7c: |
| 77 | * 00070 30 30 30 00 30 30 30 30 30 30 30 00 80 00 00 00 |000.0000000.....| |
| 78 | * 00080 00 00 00 02 13 60 00 01 31 31 31 32 30 33 33 36 |.....`..11120336| |
| 79 | * |
| 80 | * NB: tarballs with NEGATIVE unix times encoded that way were seen! |
| 81 | */ |
| 82 | v = first; |
| 83 | /* Sign-extend using 6th bit: */ |
| 84 | v <<= sizeof(unsigned long long)*8 - 7; |
| 85 | v = (long long)v >> (sizeof(unsigned long long)*8 - 7); |
| 86 | while (--len != 0) |
| 87 | v = (v << 8) + (unsigned char) *str++; |
| 88 | } |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 89 | return v; |
| 90 | } |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 91 | #define GET_OCTAL(a) getOctal((a), sizeof(a)) |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 92 | |
J. Tang | 77a2c51 | 2010-03-19 14:48:51 +0100 | [diff] [blame] | 93 | #if ENABLE_FEATURE_TAR_SELINUX |
| 94 | /* Scan a PAX header for SELinux contexts, via "RHT.security.selinux" keyword. |
| 95 | * This is what Red Hat's patched version of tar uses. |
| 96 | */ |
| 97 | # define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux" |
| 98 | static char *get_selinux_sctx_from_pax_hdr(archive_handle_t *archive_handle, unsigned sz) |
| 99 | { |
| 100 | char *buf, *p; |
| 101 | char *result; |
| 102 | |
| 103 | p = buf = xmalloc(sz + 1); |
| 104 | /* prevent bb_strtou from running off the buffer */ |
| 105 | buf[sz] = '\0'; |
| 106 | xread(archive_handle->src_fd, buf, sz); |
| 107 | archive_handle->offset += sz; |
| 108 | |
| 109 | result = NULL; |
| 110 | while (sz != 0) { |
| 111 | char *end, *value; |
| 112 | unsigned len; |
| 113 | |
| 114 | /* Every record has this format: "LEN NAME=VALUE\n" */ |
| 115 | len = bb_strtou(p, &end, 10); |
| 116 | /* expect errno to be EINVAL, because the character |
| 117 | * following the digits should be a space |
| 118 | */ |
| 119 | p += len; |
| 120 | sz -= len; |
| 121 | if ((int)sz < 0 |
| 122 | || len == 0 |
| 123 | || errno != EINVAL |
| 124 | || *end != ' ' |
| 125 | ) { |
| 126 | bb_error_msg("malformed extended header, skipped"); |
| 127 | // More verbose version: |
| 128 | //bb_error_msg("malformed extended header at %"OFF_FMT"d, skipped", |
| 129 | // archive_handle->offset - (sz + len)); |
| 130 | break; |
| 131 | } |
| 132 | /* overwrite the terminating newline with NUL |
| 133 | * (we do not bother to check that it *was* a newline) |
| 134 | */ |
| 135 | p[-1] = '\0'; |
| 136 | /* Is it selinux security context? */ |
| 137 | value = end + 1; |
| 138 | if (strncmp(value, SELINUX_CONTEXT_KEYWORD"=", sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1) == 0) { |
| 139 | value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1; |
| 140 | result = xstrdup(value); |
| 141 | break; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | free(buf); |
| 146 | return result; |
| 147 | } |
| 148 | #endif |
| 149 | |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 150 | char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 151 | { |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 152 | file_header_t *file_header = archive_handle->file_header; |
Denys Vlasenko | 52827e3 | 2010-06-26 18:21:36 +0200 | [diff] [blame] | 153 | struct tar_header_t tar; |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 154 | char *cp; |
Denis Vlasenko | a80b4a0 | 2007-06-21 12:41:59 +0000 | [diff] [blame] | 155 | int i, sum_u, sum; |
| 156 | #if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY |
| 157 | int sum_s; |
| 158 | #endif |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 159 | int parse_names; |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 160 | |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 161 | /* Our "private data" */ |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 162 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS |
Denys Vlasenko | aa4977d | 2010-01-06 10:53:17 +0100 | [diff] [blame] | 163 | # define p_longname (archive_handle->tar__longname) |
| 164 | # define p_linkname (archive_handle->tar__linkname) |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 165 | #else |
Denys Vlasenko | aa4977d | 2010-01-06 10:53:17 +0100 | [diff] [blame] | 166 | # define p_longname 0 |
| 167 | # define p_linkname 0 |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 168 | #endif |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 169 | |
J. Tang | 77a2c51 | 2010-03-19 14:48:51 +0100 | [diff] [blame] | 170 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX |
Denis Vlasenko | 666da5e | 2006-12-26 18:17:42 +0000 | [diff] [blame] | 171 | again: |
| 172 | #endif |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 173 | /* Align header */ |
Glenn L McGrath | 237ae42 | 2002-11-03 14:05:15 +0000 | [diff] [blame] | 174 | data_align(archive_handle, 512); |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 175 | |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 176 | again_after_align: |
| 177 | |
Denis Vlasenko | 1f0b95f | 2009-03-13 14:26:44 +0000 | [diff] [blame] | 178 | #if ENABLE_DESKTOP || ENABLE_FEATURE_TAR_AUTODETECT |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 179 | /* to prevent misdetection of bz2 sig */ |
Denys Vlasenko | 98a4c7c | 2010-02-04 15:00:15 +0100 | [diff] [blame] | 180 | *(aliased_uint32_t*)&tar = 0; |
Denis Vlasenko | 23ffb6a | 2008-02-13 17:52:42 +0000 | [diff] [blame] | 181 | i = full_read(archive_handle->src_fd, &tar, 512); |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 182 | /* If GNU tar sees EOF in above read, it says: |
Denis Vlasenko | 23ffb6a | 2008-02-13 17:52:42 +0000 | [diff] [blame] | 183 | * "tar: A lone zero block at N", where N = kilobyte |
| 184 | * where EOF was met (not EOF block, actual EOF!), |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 185 | * and exits with EXIT_SUCCESS. |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 186 | * We will mimic exit(EXIT_SUCCESS), although we will not mimic |
Denis Vlasenko | 12c0622 | 2008-02-14 08:52:30 +0000 | [diff] [blame] | 187 | * the message and we don't check whether we indeed |
| 188 | * saw zero block directly before this. */ |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 189 | if (i == 0) { |
Denis Vlasenko | 23ffb6a | 2008-02-13 17:52:42 +0000 | [diff] [blame] | 190 | xfunc_error_retval = 0; |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 191 | short_read: |
Denis Vlasenko | 23ffb6a | 2008-02-13 17:52:42 +0000 | [diff] [blame] | 192 | bb_error_msg_and_die("short read"); |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 193 | } |
| 194 | if (i != 512) { |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 195 | IF_FEATURE_TAR_AUTODETECT(goto autodetect;) |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 196 | goto short_read; |
| 197 | } |
| 198 | |
Denis Vlasenko | 12c0622 | 2008-02-14 08:52:30 +0000 | [diff] [blame] | 199 | #else |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 200 | i = 512; |
| 201 | xread(archive_handle->src_fd, &tar, i); |
Denis Vlasenko | 12c0622 | 2008-02-14 08:52:30 +0000 | [diff] [blame] | 202 | #endif |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 203 | archive_handle->offset += i; |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 204 | |
| 205 | /* If there is no filename its an empty header */ |
Denis Vlasenko | 05efca9 | 2008-04-29 04:12:58 +0000 | [diff] [blame] | 206 | if (tar.name[0] == 0 && tar.prefix[0] == 0) { |
Denys Vlasenko | aa4977d | 2010-01-06 10:53:17 +0100 | [diff] [blame] | 207 | if (archive_handle->tar__end) { |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 208 | /* Second consecutive empty header - end of archive. |
Paul Fox | 94ff9f1 | 2005-07-20 19:24:13 +0000 | [diff] [blame] | 209 | * Read until the end to empty the pipe from gz or bz2 |
| 210 | */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 211 | while (full_read(archive_handle->src_fd, &tar, 512) == 512) |
Denis Vlasenko | 431a7c9 | 2008-02-19 11:26:28 +0000 | [diff] [blame] | 212 | continue; |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 213 | return EXIT_FAILURE; |
Paul Fox | 94ff9f1 | 2005-07-20 19:24:13 +0000 | [diff] [blame] | 214 | } |
Denys Vlasenko | aa4977d | 2010-01-06 10:53:17 +0100 | [diff] [blame] | 215 | archive_handle->tar__end = 1; |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 216 | return EXIT_SUCCESS; |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 217 | } |
Denys Vlasenko | aa4977d | 2010-01-06 10:53:17 +0100 | [diff] [blame] | 218 | archive_handle->tar__end = 0; |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 219 | |
Denis Vlasenko | 431a7c9 | 2008-02-19 11:26:28 +0000 | [diff] [blame] | 220 | /* Check header has valid magic, "ustar" is for the proper tar, |
| 221 | * five NULs are for the old tar format */ |
| 222 | if (strncmp(tar.magic, "ustar", 5) != 0 |
| 223 | && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY |
| 224 | || memcmp(tar.magic, "\0\0\0\0", 5) != 0) |
| 225 | ) { |
| 226 | #if ENABLE_FEATURE_TAR_AUTODETECT |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 227 | char FAST_FUNC (*get_header_ptr)(archive_handle_t *); |
Denys Vlasenko | 620e863 | 2010-06-30 19:43:44 +0200 | [diff] [blame] | 228 | uint16_t magic2; |
Denis Vlasenko | 431a7c9 | 2008-02-19 11:26:28 +0000 | [diff] [blame] | 229 | |
Denis Vlasenko | 1f0b95f | 2009-03-13 14:26:44 +0000 | [diff] [blame] | 230 | autodetect: |
Denys Vlasenko | df16891 | 2011-01-16 01:25:34 +0100 | [diff] [blame] | 231 | magic2 = *(bb__aliased_uint16_t*)tar.name; |
Denis Vlasenko | 431a7c9 | 2008-02-19 11:26:28 +0000 | [diff] [blame] | 232 | /* tar gz/bz autodetect: check for gz/bz2 magic. |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 233 | * If we see the magic, and it is the very first block, |
Denis Vlasenko | 431a7c9 | 2008-02-19 11:26:28 +0000 | [diff] [blame] | 234 | * we can switch to get_header_tar_gz/bz2/lzma(). |
Denis Vlasenko | 77ad97f | 2008-05-13 02:27:31 +0000 | [diff] [blame] | 235 | * Needs seekable fd. I wish recv(MSG_PEEK) works |
Denis Vlasenko | 431a7c9 | 2008-02-19 11:26:28 +0000 | [diff] [blame] | 236 | * on any fd... */ |
Denys Vlasenko | 52827e3 | 2010-06-26 18:21:36 +0200 | [diff] [blame] | 237 | # if ENABLE_FEATURE_SEAMLESS_GZ |
Denys Vlasenko | 620e863 | 2010-06-30 19:43:44 +0200 | [diff] [blame] | 238 | if (magic2 == GZIP_MAGIC) { |
Denis Vlasenko | 431a7c9 | 2008-02-19 11:26:28 +0000 | [diff] [blame] | 239 | get_header_ptr = get_header_tar_gz; |
| 240 | } else |
Denys Vlasenko | 52827e3 | 2010-06-26 18:21:36 +0200 | [diff] [blame] | 241 | # endif |
| 242 | # if ENABLE_FEATURE_SEAMLESS_BZ2 |
Denys Vlasenko | 620e863 | 2010-06-30 19:43:44 +0200 | [diff] [blame] | 243 | if (magic2 == BZIP2_MAGIC |
Denis Vlasenko | 431a7c9 | 2008-02-19 11:26:28 +0000 | [diff] [blame] | 244 | && tar.name[2] == 'h' && isdigit(tar.name[3]) |
| 245 | ) { /* bzip2 */ |
| 246 | get_header_ptr = get_header_tar_bz2; |
| 247 | } else |
Denys Vlasenko | 52827e3 | 2010-06-26 18:21:36 +0200 | [diff] [blame] | 248 | # endif |
| 249 | # if ENABLE_FEATURE_SEAMLESS_XZ |
Denys Vlasenko | 620e863 | 2010-06-30 19:43:44 +0200 | [diff] [blame] | 250 | //TODO: if (magic2 == XZ_MAGIC1)... |
| 251 | //else |
Denys Vlasenko | 52827e3 | 2010-06-26 18:21:36 +0200 | [diff] [blame] | 252 | # endif |
Denis Vlasenko | 431a7c9 | 2008-02-19 11:26:28 +0000 | [diff] [blame] | 253 | goto err; |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 254 | /* Two different causes for lseek() != 0: |
| 255 | * unseekable fd (would like to support that too, but...), |
| 256 | * or not first block (false positive, it's not .gz/.bz2!) */ |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 257 | if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0) |
Denis Vlasenko | 431a7c9 | 2008-02-19 11:26:28 +0000 | [diff] [blame] | 258 | goto err; |
| 259 | while (get_header_ptr(archive_handle) == EXIT_SUCCESS) |
| 260 | continue; |
| 261 | return EXIT_FAILURE; |
| 262 | err: |
| 263 | #endif /* FEATURE_TAR_AUTODETECT */ |
| 264 | bb_error_msg_and_die("invalid tar magic"); |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 265 | } |
Denis Vlasenko | dcbd51d | 2007-03-03 20:06:59 +0000 | [diff] [blame] | 266 | |
| 267 | /* Do checksum on headers. |
| 268 | * POSIX says that checksum is done on unsigned bytes, but |
Denis Vlasenko | 940494f | 2007-03-04 18:09:50 +0000 | [diff] [blame] | 269 | * Sun and HP-UX gets it wrong... more details in |
Denis Vlasenko | dcbd51d | 2007-03-03 20:06:59 +0000 | [diff] [blame] | 270 | * GNU tar source. */ |
Denis Vlasenko | a80b4a0 | 2007-06-21 12:41:59 +0000 | [diff] [blame] | 271 | #if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY |
| 272 | sum_s = ' ' * sizeof(tar.chksum); |
| 273 | #endif |
| 274 | sum_u = ' ' * sizeof(tar.chksum); |
Denis Vlasenko | b71c668 | 2007-07-21 15:08:09 +0000 | [diff] [blame] | 275 | for (i = 0; i < 148; i++) { |
Denis Vlasenko | dcbd51d | 2007-03-03 20:06:59 +0000 | [diff] [blame] | 276 | sum_u += ((unsigned char*)&tar)[i]; |
Denis Vlasenko | a80b4a0 | 2007-06-21 12:41:59 +0000 | [diff] [blame] | 277 | #if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY |
Denis Vlasenko | dcbd51d | 2007-03-03 20:06:59 +0000 | [diff] [blame] | 278 | sum_s += ((signed char*)&tar)[i]; |
Denis Vlasenko | a80b4a0 | 2007-06-21 12:41:59 +0000 | [diff] [blame] | 279 | #endif |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 280 | } |
Denis Vlasenko | b71c668 | 2007-07-21 15:08:09 +0000 | [diff] [blame] | 281 | for (i = 156; i < 512; i++) { |
Denis Vlasenko | dcbd51d | 2007-03-03 20:06:59 +0000 | [diff] [blame] | 282 | sum_u += ((unsigned char*)&tar)[i]; |
Denis Vlasenko | a80b4a0 | 2007-06-21 12:41:59 +0000 | [diff] [blame] | 283 | #if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY |
Denis Vlasenko | dcbd51d | 2007-03-03 20:06:59 +0000 | [diff] [blame] | 284 | sum_s += ((signed char*)&tar)[i]; |
Denis Vlasenko | a80b4a0 | 2007-06-21 12:41:59 +0000 | [diff] [blame] | 285 | #endif |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 286 | } |
Denis Vlasenko | a80b4a0 | 2007-06-21 12:41:59 +0000 | [diff] [blame] | 287 | /* This field does not need special treatment (getOctal) */ |
Denys Vlasenko | 8d33817 | 2009-09-23 17:16:37 +0200 | [diff] [blame] | 288 | { |
| 289 | char *endp; /* gcc likes temp var for &endp */ |
| 290 | sum = strtoul(tar.chksum, &endp, 8); |
| 291 | if ((*endp != '\0' && *endp != ' ') |
| 292 | || (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) |
| 293 | ) { |
| 294 | bb_error_msg_and_die("invalid tar header checksum"); |
| 295 | } |
| 296 | } |
Denys Vlasenko | d645968 | 2010-01-03 23:41:11 +0100 | [diff] [blame] | 297 | /* don't use xstrtoul, tar.chksum may have leading spaces */ |
| 298 | sum = strtoul(tar.chksum, NULL, 8); |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 299 | if (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) { |
Denis Vlasenko | a80b4a0 | 2007-06-21 12:41:59 +0000 | [diff] [blame] | 300 | bb_error_msg_and_die("invalid tar header checksum"); |
| 301 | } |
Glenn L McGrath | 95ebf61 | 2001-10-25 14:18:08 +0000 | [diff] [blame] | 302 | |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 303 | /* 0 is reserved for high perf file, treat as normal file */ |
| 304 | if (!tar.typeflag) tar.typeflag = '0'; |
| 305 | parse_names = (tar.typeflag >= '0' && tar.typeflag <= '7'); |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 306 | |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 307 | /* getOctal trashes subsequent field, therefore we call it |
| 308 | * on fields in reverse order */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 309 | if (tar.devmajor[0]) { |
Denis Vlasenko | d93400b | 2008-04-29 03:54:16 +0000 | [diff] [blame] | 310 | char t = tar.prefix[0]; |
| 311 | /* we trash prefix[0] here, but we DO need it later! */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 312 | unsigned minor = GET_OCTAL(tar.devminor); |
| 313 | unsigned major = GET_OCTAL(tar.devmajor); |
| 314 | file_header->device = makedev(major, minor); |
Denis Vlasenko | d93400b | 2008-04-29 03:54:16 +0000 | [diff] [blame] | 315 | tar.prefix[0] = t; |
Denis Vlasenko | cba9ef5 | 2006-10-10 21:00:47 +0000 | [diff] [blame] | 316 | } |
Denis Vlasenko | 7510384 | 2007-06-20 14:49:47 +0000 | [diff] [blame] | 317 | file_header->link_target = NULL; |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 318 | if (!p_linkname && parse_names && tar.linkname[0]) { |
Denis Vlasenko | bc1918a | 2008-04-15 01:17:50 +0000 | [diff] [blame] | 319 | file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname)); |
Denis Vlasenko | 7510384 | 2007-06-20 14:49:47 +0000 | [diff] [blame] | 320 | /* FIXME: what if we have non-link object with link_target? */ |
| 321 | /* Will link_target be free()ed? */ |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 322 | } |
Denis Vlasenko | e00e502 | 2008-02-14 20:37:54 +0000 | [diff] [blame] | 323 | #if ENABLE_FEATURE_TAR_UNAME_GNAME |
Denys Vlasenko | aa4977d | 2010-01-06 10:53:17 +0100 | [diff] [blame] | 324 | file_header->tar__uname = tar.uname[0] ? xstrndup(tar.uname, sizeof(tar.uname)) : NULL; |
| 325 | file_header->tar__gname = tar.gname[0] ? xstrndup(tar.gname, sizeof(tar.gname)) : NULL; |
Denis Vlasenko | e00e502 | 2008-02-14 20:37:54 +0000 | [diff] [blame] | 326 | #endif |
Denys Vlasenko | 7b48eb4 | 2010-05-06 20:08:14 +0200 | [diff] [blame] | 327 | file_header->mtime = GET_OCTAL(tar.mtime); |
| 328 | file_header->size = GET_OCTAL(tar.size); |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 329 | file_header->gid = GET_OCTAL(tar.gid); |
| 330 | file_header->uid = GET_OCTAL(tar.uid); |
Glenn L McGrath | 916ba53 | 2004-02-20 02:34:42 +0000 | [diff] [blame] | 331 | /* Set bits 0-11 of the files mode */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 332 | file_header->mode = 07777 & GET_OCTAL(tar.mode); |
Glenn L McGrath | 916ba53 | 2004-02-20 02:34:42 +0000 | [diff] [blame] | 333 | |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 334 | file_header->name = NULL; |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 335 | if (!p_longname && parse_names) { |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 336 | /* we trash mode[0] here, it's ok */ |
Denis Vlasenko | bc1918a | 2008-04-15 01:17:50 +0000 | [diff] [blame] | 337 | //tar.name[sizeof(tar.name)] = '\0'; - gcc 4.3.0 would complain |
| 338 | tar.mode[0] = '\0'; |
Denis Vlasenko | 87cd4a8 | 2006-11-25 23:47:32 +0000 | [diff] [blame] | 339 | if (tar.prefix[0]) { |
| 340 | /* and padding[0] */ |
Denis Vlasenko | bc1918a | 2008-04-15 01:17:50 +0000 | [diff] [blame] | 341 | //tar.prefix[sizeof(tar.prefix)] = '\0'; - gcc 4.3.0 would complain |
| 342 | tar.padding[0] = '\0'; |
Denis Vlasenko | cf30cc8 | 2006-11-24 14:53:18 +0000 | [diff] [blame] | 343 | file_header->name = concat_path_file(tar.prefix, tar.name); |
Denis Vlasenko | 87cd4a8 | 2006-11-25 23:47:32 +0000 | [diff] [blame] | 344 | } else |
Denis Vlasenko | cf30cc8 | 2006-11-24 14:53:18 +0000 | [diff] [blame] | 345 | file_header->name = xstrdup(tar.name); |
| 346 | } |
| 347 | |
Glenn L McGrath | 916ba53 | 2004-02-20 02:34:42 +0000 | [diff] [blame] | 348 | /* Set bits 12-15 of the files mode */ |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 349 | /* (typeflag was not trashed because chksum does not use getOctal) */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 350 | switch (tar.typeflag) { |
Ian Wienand | 954dbd3 | 2011-07-29 08:33:47 +0200 | [diff] [blame] | 351 | case '1': /* hardlink */ |
| 352 | /* we mark hardlinks as regular files with zero size and a link name */ |
Glenn L McGrath | 916ba53 | 2004-02-20 02:34:42 +0000 | [diff] [blame] | 353 | file_header->mode |= S_IFREG; |
Ian Wienand | 954dbd3 | 2011-07-29 08:33:47 +0200 | [diff] [blame] | 354 | /* on size of link fields from star(4) |
| 355 | * ... For tar archives written by pre POSIX.1-1988 |
| 356 | * implementations, the size field usually contains the size of |
| 357 | * the file and needs to be ignored as no data may follow this |
| 358 | * header type. For POSIX.1- 1988 compliant archives, the size |
| 359 | * field needs to be 0. For POSIX.1-2001 compliant archives, |
| 360 | * the size field may be non zero, indicating that file data is |
| 361 | * included in the archive. |
| 362 | * i.e; always assume this is zero for safety. |
| 363 | */ |
| 364 | goto size0; |
Glenn L McGrath | c9f1fce | 2004-02-20 02:25:18 +0000 | [diff] [blame] | 365 | case '7': |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 366 | /* case 0: */ |
Glenn L McGrath | 21110a0 | 2003-01-28 01:45:48 +0000 | [diff] [blame] | 367 | case '0': |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 368 | #if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY |
Glenn L McGrath | 87af49f | 2003-09-09 17:41:03 +0000 | [diff] [blame] | 369 | if (last_char_is(file_header->name, '/')) { |
Denis Vlasenko | adc772a | 2008-07-20 17:10:43 +0000 | [diff] [blame] | 370 | goto set_dir; |
| 371 | } |
Glenn L McGrath | c9f1fce | 2004-02-20 02:25:18 +0000 | [diff] [blame] | 372 | #endif |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 373 | file_header->mode |= S_IFREG; |
Glenn L McGrath | 99b1254 | 2002-08-22 17:47:09 +0000 | [diff] [blame] | 374 | break; |
Glenn L McGrath | 21110a0 | 2003-01-28 01:45:48 +0000 | [diff] [blame] | 375 | case '2': |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 376 | file_header->mode |= S_IFLNK; |
Denis Vlasenko | adc772a | 2008-07-20 17:10:43 +0000 | [diff] [blame] | 377 | /* have seen tarballs with size field containing |
| 378 | * the size of the link target's name */ |
| 379 | size0: |
| 380 | file_header->size = 0; |
Glenn L McGrath | 99b1254 | 2002-08-22 17:47:09 +0000 | [diff] [blame] | 381 | break; |
Glenn L McGrath | 21110a0 | 2003-01-28 01:45:48 +0000 | [diff] [blame] | 382 | case '3': |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 383 | file_header->mode |= S_IFCHR; |
Denis Vlasenko | adc772a | 2008-07-20 17:10:43 +0000 | [diff] [blame] | 384 | goto size0; /* paranoia */ |
Glenn L McGrath | 21110a0 | 2003-01-28 01:45:48 +0000 | [diff] [blame] | 385 | case '4': |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 386 | file_header->mode |= S_IFBLK; |
Denis Vlasenko | adc772a | 2008-07-20 17:10:43 +0000 | [diff] [blame] | 387 | goto size0; |
Glenn L McGrath | 21110a0 | 2003-01-28 01:45:48 +0000 | [diff] [blame] | 388 | case '5': |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 389 | IF_FEATURE_TAR_OLDGNU_COMPATIBILITY(set_dir:) |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 390 | file_header->mode |= S_IFDIR; |
Denis Vlasenko | adc772a | 2008-07-20 17:10:43 +0000 | [diff] [blame] | 391 | goto size0; |
Glenn L McGrath | 21110a0 | 2003-01-28 01:45:48 +0000 | [diff] [blame] | 392 | case '6': |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 393 | file_header->mode |= S_IFIFO; |
Denis Vlasenko | adc772a | 2008-07-20 17:10:43 +0000 | [diff] [blame] | 394 | goto size0; |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 395 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 396 | case 'L': |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 397 | /* free: paranoia: tar with several consecutive longnames */ |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 398 | free(p_longname); |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 399 | /* For paranoia reasons we allocate extra NUL char */ |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 400 | p_longname = xzalloc(file_header->size + 1); |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 401 | /* We read ASCIZ string, including NUL */ |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 402 | xread(archive_handle->src_fd, p_longname, file_header->size); |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 403 | archive_handle->offset += file_header->size; |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 404 | /* return get_header_tar(archive_handle); */ |
| 405 | /* gcc 4.1.1 didn't optimize it into jump */ |
| 406 | /* so we will do it ourself, this also saves stack */ |
| 407 | goto again; |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 408 | case 'K': |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 409 | free(p_linkname); |
| 410 | p_linkname = xzalloc(file_header->size + 1); |
| 411 | xread(archive_handle->src_fd, p_linkname, file_header->size); |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 412 | archive_handle->offset += file_header->size; |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 413 | /* return get_header_tar(archive_handle); */ |
| 414 | goto again; |
Glenn L McGrath | b0e163a | 2004-02-19 08:48:30 +0000 | [diff] [blame] | 415 | case 'D': /* GNU dump dir */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 416 | case 'M': /* Continuation of multi volume archive */ |
Glenn L McGrath | b0e163a | 2004-02-19 08:48:30 +0000 | [diff] [blame] | 417 | case 'N': /* Old GNU for names > 100 characters */ |
| 418 | case 'S': /* Sparse file */ |
| 419 | case 'V': /* Volume header */ |
Glenn L McGrath | 6aa5223 | 2004-02-17 11:55:06 +0000 | [diff] [blame] | 420 | #endif |
J. Tang | 77a2c51 | 2010-03-19 14:48:51 +0100 | [diff] [blame] | 421 | #if !ENABLE_FEATURE_TAR_SELINUX |
Rob Landley | ff6e21c | 2006-07-06 20:30:19 +0000 | [diff] [blame] | 422 | case 'g': /* pax global header */ |
J. Tang | 77a2c51 | 2010-03-19 14:48:51 +0100 | [diff] [blame] | 423 | case 'x': /* pax extended header */ |
| 424 | #else |
| 425 | skip_ext_hdr: |
| 426 | #endif |
| 427 | { |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 428 | off_t sz; |
| 429 | bb_error_msg("warning: skipping header '%c'", tar.typeflag); |
| 430 | sz = (file_header->size + 511) & ~(off_t)511; |
| 431 | archive_handle->offset += sz; |
| 432 | sz >>= 9; /* sz /= 512 but w/o contortions for signed div */ |
| 433 | while (sz--) |
| 434 | xread(archive_handle->src_fd, &tar, 512); |
| 435 | /* return get_header_tar(archive_handle); */ |
| 436 | goto again_after_align; |
| 437 | } |
J. Tang | 77a2c51 | 2010-03-19 14:48:51 +0100 | [diff] [blame] | 438 | #if ENABLE_FEATURE_TAR_SELINUX |
| 439 | case 'g': /* pax global header */ |
| 440 | case 'x': { /* pax extended header */ |
| 441 | char **pp; |
| 442 | if ((uoff_t)file_header->size > 0xfffff) /* paranoia */ |
| 443 | goto skip_ext_hdr; |
| 444 | pp = (tar.typeflag == 'g') ? &archive_handle->tar__global_sctx : &archive_handle->tar__next_file_sctx; |
| 445 | free(*pp); |
| 446 | *pp = get_selinux_sctx_from_pax_hdr(archive_handle, file_header->size); |
| 447 | goto again; |
| 448 | } |
| 449 | #endif |
Glenn L McGrath | b0e163a | 2004-02-19 08:48:30 +0000 | [diff] [blame] | 450 | default: |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 451 | bb_error_msg_and_die("unknown typeflag: 0x%x", tar.typeflag); |
Glenn L McGrath | 6aa5223 | 2004-02-17 11:55:06 +0000 | [diff] [blame] | 452 | } |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 453 | |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 454 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 455 | if (p_longname) { |
| 456 | file_header->name = p_longname; |
| 457 | p_longname = NULL; |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 458 | } |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 459 | if (p_linkname) { |
| 460 | file_header->link_target = p_linkname; |
| 461 | p_linkname = NULL; |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 462 | } |
| 463 | #endif |
Denys Vlasenko | 5e29e26 | 2011-03-01 17:21:07 +0100 | [diff] [blame] | 464 | |
| 465 | /* Everything up to and including last ".." component is stripped */ |
Denys Vlasenko | b80acf5 | 2011-03-02 01:21:02 +0100 | [diff] [blame] | 466 | overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name)); |
Denis Vlasenko | d677250 | 2006-11-24 17:21:44 +0000 | [diff] [blame] | 467 | |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 468 | /* Strip trailing '/' in directories */ |
Denis Vlasenko | 714701c | 2006-12-22 00:21:07 +0000 | [diff] [blame] | 469 | /* Must be done after mode is set as '/' is used to check if it's a directory */ |
Denis Vlasenko | 376ce1e | 2006-11-24 14:51:01 +0000 | [diff] [blame] | 470 | cp = last_char_is(file_header->name, '/'); |
Glenn L McGrath | 3d5828f | 2003-08-14 02:55:15 +0000 | [diff] [blame] | 471 | |
Glenn L McGrath | 8e94098 | 2002-11-04 23:47:31 +0000 | [diff] [blame] | 472 | if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { |
Denis Vlasenko | 0381d42 | 2008-07-10 23:06:00 +0000 | [diff] [blame] | 473 | archive_handle->action_header(/*archive_handle->*/ file_header); |
Denis Vlasenko | cf30cc8 | 2006-11-24 14:53:18 +0000 | [diff] [blame] | 474 | /* Note that we kill the '/' only after action_header() */ |
| 475 | /* (like GNU tar 1.15.1: verbose mode outputs "dir/dir/") */ |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 476 | if (cp) |
| 477 | *cp = '\0'; |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 478 | archive_handle->action_data(archive_handle); |
Denys Vlasenko | b768aeb | 2010-06-26 18:22:41 +0200 | [diff] [blame] | 479 | if (archive_handle->accept || archive_handle->reject) |
| 480 | llist_add_to(&archive_handle->passed, file_header->name); |
| 481 | else /* Caller isn't interested in list of unpacked files */ |
| 482 | free(file_header->name); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 483 | } else { |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 484 | data_skip(archive_handle); |
Denis Vlasenko | b596335 | 2006-11-26 01:46:59 +0000 | [diff] [blame] | 485 | free(file_header->name); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 486 | } |
| 487 | archive_handle->offset += file_header->size; |
| 488 | |
Denis Vlasenko | 7510384 | 2007-06-20 14:49:47 +0000 | [diff] [blame] | 489 | free(file_header->link_target); |
Denys Vlasenko | b768aeb | 2010-06-26 18:22:41 +0200 | [diff] [blame] | 490 | /* Do not free(file_header->name)! |
| 491 | * It might be inserted in archive_handle->passed - see above */ |
Denis Vlasenko | e00e502 | 2008-02-14 20:37:54 +0000 | [diff] [blame] | 492 | #if ENABLE_FEATURE_TAR_UNAME_GNAME |
Denys Vlasenko | aa4977d | 2010-01-06 10:53:17 +0100 | [diff] [blame] | 493 | free(file_header->tar__uname); |
| 494 | free(file_header->tar__gname); |
Denis Vlasenko | e00e502 | 2008-02-14 20:37:54 +0000 | [diff] [blame] | 495 | #endif |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 496 | return EXIT_SUCCESS; |
Eric Andersen | 2276d83 | 2002-07-11 11:11:56 +0000 | [diff] [blame] | 497 | } |