busybox/archival/libarchive/unsafe_prefix.c
<<
>>
Prefs
   1/* vi: set sw=4 ts=4: */
   2/*
   3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
   4 */
   5#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                }
  17                if (is_prefixed_with(cp, "/../"+1)) {
  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}
  36