Denys Vlasenko | 8c06bc6 | 2015-02-10 01:30:43 +0100 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
| 4 | */ |
Denys Vlasenko | 8c06bc6 | 2015-02-10 01:30:43 +0100 | [diff] [blame] | 5 | #include "libbb.h" |
| 6 | #include "bb_archive.h" |
| 7 | |
| 8 | const char* FAST_FUNC strip_unsafe_prefix(const char *str) |
| 9 | { |
| 10 | const char *cp = str; |
| 11 | while (1) { |
| 12 | char *cp2; |
| 13 | if (*cp == '/') { |
| 14 | cp++; |
| 15 | continue; |
| 16 | } |
Denys Vlasenko | 8dff01d | 2015-03-12 17:48:34 +0100 | [diff] [blame] | 17 | if (is_prefixed_with(cp, "/../"+1)) { |
Denys Vlasenko | 8c06bc6 | 2015-02-10 01:30:43 +0100 | [diff] [blame] | 18 | cp += 3; |
| 19 | continue; |
| 20 | } |
| 21 | cp2 = strstr(cp, "/../"); |
| 22 | if (!cp2) |
| 23 | break; |
| 24 | cp = cp2 + 4; |
| 25 | } |
| 26 | if (cp != str) { |
| 27 | static smallint warned = 0; |
| 28 | if (!warned) { |
| 29 | warned = 1; |
| 30 | bb_error_msg("removing leading '%.*s' from member names", |
| 31 | (int)(cp - str), str); |
| 32 | } |
| 33 | } |
| 34 | return cp; |
| 35 | } |