busybox: update to 1.25.0
[tomato.git] / release / src / router / busybox / archival / libarchive / unsafe_prefix.c
blob9994f4d94edf01f2815507a8b2ba1d7315d2171f
1 /* vi: set sw=4 ts=4: */
2 /*
3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
4 */
6 #include "libbb.h"
7 #include "bb_archive.h"
9 const char* FAST_FUNC strip_unsafe_prefix(const char *str)
11 const char *cp = str;
12 while (1) {
13 char *cp2;
14 if (*cp == '/') {
15 cp++;
16 continue;
18 if (is_prefixed_with(cp, "/../"+1)) {
19 cp += 3;
20 continue;
22 cp2 = strstr(cp, "/../");
23 if (!cp2)
24 break;
25 cp = cp2 + 4;
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);
35 return cp;