blob: 9994f4d94edf01f2815507a8b2ba1d7315d2171f [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 */
5
6#include "libbb.h"
7#include "bb_archive.h"
8
9const 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 }
Denys Vlasenko8dff01d2015-03-12 17:48:34 +010018 if (is_prefixed_with(cp, "/../"+1)) {
Denys Vlasenko8c06bc62015-02-10 01:30:43 +010019 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}