blob: 33e487bf9455dfef2bf77d2e094de1c2062c1cea [file] [log] [blame]
Denys Vlasenko8c06bc62015-02-10 01:30:43 +01001/* vi: set sw=4 ts=4: */
2/*
3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
4 */
Denys Vlasenko8c06bc62015-02-10 01:30:43 +01005#include "libbb.h"
6#include "bb_archive.h"
7
8const 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 Vlasenko8dff01d2015-03-12 17:48:34 +010017 if (is_prefixed_with(cp, "/../"+1)) {
Denys Vlasenko8c06bc62015-02-10 01:30:43 +010018 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}