unsafe_prefix.c 632 B

123456789101112131415161718192021222324252627282930313233343536
  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. const char* FAST_FUNC strip_unsafe_prefix(const char *str)
  8. {
  9. const char *cp = str;
  10. while (1) {
  11. char *cp2;
  12. if (*cp == '/') {
  13. cp++;
  14. continue;
  15. }
  16. if (is_prefixed_with(cp, "/../"+1)) {
  17. cp += 3;
  18. continue;
  19. }
  20. cp2 = strstr(cp, "/../");
  21. if (!cp2)
  22. break;
  23. cp = cp2 + 4;
  24. }
  25. if (cp != str) {
  26. static smallint warned = 0;
  27. if (!warned) {
  28. warned = 1;
  29. bb_error_msg("removing leading '%.*s' from member names",
  30. (int)(cp - str), str);
  31. }
  32. }
  33. return cp;
  34. }