ash: remove superfluous code in arithmetic mode
[oweals/busybox.git] / archival / libarchive / unsafe_prefix.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
4  */
5
6 #include "libbb.h"
7 #include "bb_archive.h"
8
9 const char* FAST_FUNC strip_unsafe_prefix(const char *str)
10 {
11         const char *cp = str;
12         while (1) {
13                 char *cp2;
14                 if (*cp == '/') {
15                         cp++;
16                         continue;
17                 }
18                 if (is_prefixed_with(cp, "/../"+1)) {
19                         cp += 3;
20                         continue;
21                 }
22                 cp2 = strstr(cp, "/../");
23                 if (!cp2)
24                         break;
25                 cp = cp2 + 4;
26         }
27         if (cp != str) {
28                 static smallint warned = 0;
29                 if (!warned) {
30                         warned = 1;
31                         bb_error_msg("removing leading '%.*s' from member names",
32                                 (int)(cp - str), str);
33                 }
34         }
35         return cp;
36 }