aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-09-23 17:16:37 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-09-23 17:16:37 +0200
commit8d338173a4668740b1ab4a40d1d26cd25402e406 (patch)
treec6d66f3b4a083eb8ecd20830b1cb8485f8ac179c
parent844f9909264b7f46620e06b7116facba0a940667 (diff)
downloadbusybox-w32-8d338173a4668740b1ab4a40d1d26cd25402e406.tar.gz
busybox-w32-8d338173a4668740b1ab4a40d1d26cd25402e406.tar.bz2
busybox-w32-8d338173a4668740b1ab4a40d1d26cd25402e406.zip
tar: accept spaces at the end of header fields (compat)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/libunarchive/get_header_tar.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index 71e08bf7d..b8d7648ec 100644
--- a/archival/libunarchive/get_header_tar.c
+++ b/archival/libunarchive/get_header_tar.c
@@ -87,11 +87,13 @@ static unsigned long long getOctal(char *str, int len)
87{ 87{
88 unsigned long long v; 88 unsigned long long v;
89 /* NB: leading spaces are allowed. Using strtoull to handle that. 89 /* NB: leading spaces are allowed. Using strtoull to handle that.
90 * The downside is that we accept e.g. "-123" too :) 90 * The downside is that we accept e.g. "-123" too :(
91 */ 91 */
92 str[len] = '\0'; 92 str[len] = '\0';
93 v = strtoull(str, &str, 8); 93 v = strtoull(str, &str, 8);
94 if (*str && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY || *str != ' ')) 94 /* std: "Each numeric field is terminated by one or more
95 * <space> or NUL characters". We must support ' '! */
96 if (*str != '\0' && *str != ' ')
95 bb_error_msg_and_die("corrupted octal value in tar header"); 97 bb_error_msg_and_die("corrupted octal value in tar header");
96 return v; 98 return v;
97} 99}
@@ -262,20 +264,20 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
262 sum_s += ((signed char*)&tar)[i]; 264 sum_s += ((signed char*)&tar)[i];
263#endif 265#endif
264 } 266 }
265#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
266 sum = strtoul(tar.chksum, &cp, 8);
267 if ((*cp && *cp != ' ')
268 || (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum))
269 ) {
270 bb_error_msg_and_die("invalid tar header checksum");
271 }
272#else
273 /* This field does not need special treatment (getOctal) */ 267 /* This field does not need special treatment (getOctal) */
268 {
269 char *endp; /* gcc likes temp var for &endp */
270 sum = strtoul(tar.chksum, &endp, 8);
271 if ((*endp != '\0' && *endp != ' ')
272 || (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum))
273 ) {
274 bb_error_msg_and_die("invalid tar header checksum");
275 }
276 }
274 sum = xstrtoul(tar.chksum, 8); 277 sum = xstrtoul(tar.chksum, 8);
275 if (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) { 278 if (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) {
276 bb_error_msg_and_die("invalid tar header checksum"); 279 bb_error_msg_and_die("invalid tar header checksum");
277 } 280 }
278#endif
279 281
280 /* 0 is reserved for high perf file, treat as normal file */ 282 /* 0 is reserved for high perf file, treat as normal file */
281 if (!tar.typeflag) tar.typeflag = '0'; 283 if (!tar.typeflag) tar.typeflag = '0';