summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2016-02-15 02:38:54 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2016-02-15 02:38:54 +0000
commit0f6af553e94b205cddf287a90d4fac6b885e5ec4 (patch)
treecb8a4ccba29423503c1f7888f18713b13e222249
parentb2f670eaf3e2f6de453b74ef49649e5ac56d014d (diff)
To archive a 101 character absolute path in ustar format we must
split it on a slash other than the leading one. Fix based on patches from Peter Fokker (openbsd (at) berestijn.nl) and Peter Bisroev (peter (at) int19h.net)
-rw-r--r--bin/pax/tar.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/bin/pax/tar.c b/bin/pax/tar.c
index ba8b3e8ede8..3a8b2600f63 100644
--- a/bin/pax/tar.c
+++ b/bin/pax/tar.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tar.c,v 1.58 2015/03/17 03:23:17 guenther Exp $ */
+/* $OpenBSD: tar.c,v 1.59 2016/02/15 02:38:53 guenther Exp $ */
/* $NetBSD: tar.c,v 1.5 1995/03/21 09:07:49 cgd Exp $ */
/*-
@@ -1159,6 +1159,16 @@ name_split(char *name, int len)
* include the slash between the two parts that gets thrown away)
*/
start = name + len - TNMSZ - 1;
+
+ /*
+ * the prefix may not be empty, so skip the first character when
+ * trying to split a path of exactly TNMSZ+1 characters.
+ * NOTE: This means the ustar format can't store /str if
+ * str contains no slashes and the length of str == TNMSZ
+ */
+ if (start == name)
+ ++start;
+
while ((*start != '\0') && (*start != '/'))
++start;
@@ -1168,15 +1178,12 @@ name_split(char *name, int len)
*/
if (*start == '\0')
return(NULL);
- len = start - name;
/*
- * NOTE: /str where the length of str == TNMSZ can not be stored under
- * the p1003.1-1990 spec for ustar. We could force a prefix of / and
- * the file would then expand on extract to //str. The len == 0 below
- * makes this special case follow the spec to the letter.
+ * the split point isn't valid if it results in a prefix
+ * longer than TPFSZ
*/
- if ((len > TPFSZ) || (len == 0))
+ if ((start - name) > TPFSZ)
return(NULL);
/*