summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2015-02-12 23:01:58 +0000
committerguenther <guenther@openbsd.org>2015-02-12 23:01:58 +0000
commit14757f6f8dbb3eeb44f4266bbd58af2f2804e2ae (patch)
tree3f54a9ca451557a620bab956551457882ae844d1
parentConvert to if_input(). (diff)
downloadwireguard-openbsd-14757f6f8dbb3eeb44f4266bbd58af2f2804e2ae.tar.xz
wireguard-openbsd-14757f6f8dbb3eeb44f4266bbd58af2f2804e2ae.zip
For tar without -P, if a path in the archive has any ".." components then
strip everything up to and including the last of them (if it ends in ".." then it becomes ".") This mostly follows GNU tar's behavior, except for 'tar tf' and 'tar xvf' we report the modified path that was actually created instead of the raw path from the archive ok w/tweak millert@, deraadt@
-rw-r--r--bin/pax/pat_rep.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/bin/pax/pat_rep.c b/bin/pax/pat_rep.c
index a78109065c8..6f3eb1bf98b 100644
--- a/bin/pax/pat_rep.c
+++ b/bin/pax/pat_rep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pat_rep.c,v 1.34 2014/05/24 18:51:00 guenther Exp $ */
+/* $OpenBSD: pat_rep.c,v 1.35 2015/02/12 23:01:58 guenther Exp $ */
/* $NetBSD: pat_rep.c,v 1.4 1995/03/21 09:07:33 cgd Exp $ */
/*-
@@ -632,6 +632,30 @@ mod_name(ARCHD *arcn)
paxwarn(0, "Removing leading / from absolute path names in the archive");
}
}
+ if (rmleadslash) {
+ const char *last = NULL;
+ const char *p = arcn->name;
+
+ while ((p = strstr(p, "..")) != NULL) {
+ if ((p == arcn->name || p[-1] == '/') &&
+ (p[2] == '/' || p[2] == '\0'))
+ last = p + 2;
+ p += 2;
+ }
+ if (last != NULL) {
+ last++;
+ paxwarn(1, "Removing leading \"%.*s\"",
+ (int)(last - arcn->name), arcn->name);
+ arcn->nlen = strlen(last);
+ if (arcn->nlen > 0)
+ memmove(arcn->name, last, arcn->nlen + 1);
+ else {
+ arcn->name[0] = '.';
+ arcn->name[1] = '\0';
+ arcn->nlen = 1;
+ }
+ }
+ }
/*
* IMPORTANT: We have a problem. what do we do with symlinks?