diff options
Diffstat (limited to 'archival/libarchive/unsafe_prefix.c')
-rw-r--r-- | archival/libarchive/unsafe_prefix.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/archival/libarchive/unsafe_prefix.c b/archival/libarchive/unsafe_prefix.c new file mode 100644 index 000000000..826c673bf --- /dev/null +++ b/archival/libarchive/unsafe_prefix.c | |||
@@ -0,0 +1,36 @@ | |||
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 (strncmp(cp, "/../"+1, 3) == 0) { | ||
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 | } | ||