You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.8 KiB

  1. From d0fe86177427e0c3bc2cec1436d74472e4b618dd Mon Sep 17 00:00:00 2001
  2. From: Muh Muhten <muh.muhten@gmail.com>
  3. Date: Tue, 19 Feb 2019 00:35:40 -0500
  4. Subject: [PATCH 5/9] Catch .. as the first component of a module path
  5. Only the second and subsequent path components were being checked, which
  6. I guess is theoretically security-relevant.
  7. There's no apparent point to reconstructing the path after splitting it
  8. by adding /s back in, either.
  9. ---
  10. src/linker.c | 9 ++-------
  11. 1 file changed, 2 insertions(+), 7 deletions(-)
  12. --- a/src/linker.c
  13. +++ b/src/linker.c
  14. @@ -98,12 +98,9 @@ static jv validate_relpath(jv name) {
  15. return res;
  16. }
  17. jv components = jv_string_split(jv_copy(name), jv_string("/"));
  18. - jv rp = jv_array_get(jv_copy(components), 0);
  19. - components = jv_array_slice(components, 1, jv_array_length(jv_copy(components)));
  20. jv_array_foreach(components, i, x) {
  21. if (!strcmp(jv_string_value(x), "..")) {
  22. jv_free(x);
  23. - jv_free(rp);
  24. jv_free(components);
  25. jv res = jv_invalid_with_msg(jv_string_fmt("Relative paths to modules may not traverse to parent directories (%s)", s));
  26. jv_free(name);
  27. @@ -111,18 +108,16 @@ static jv validate_relpath(jv name) {
  28. }
  29. if (i > 0 && jv_equal(jv_copy(x), jv_array_get(jv_copy(components), i - 1))) {
  30. jv_free(x);
  31. - jv_free(rp);
  32. jv_free(components);
  33. jv res = jv_invalid_with_msg(jv_string_fmt("module names must not have equal consecutive components: %s",
  34. jv_string_value(name)));
  35. jv_free(name);
  36. return res;
  37. }
  38. - rp = jv_string_concat(rp, jv_string_concat(jv_string("/"), x));
  39. + jv_free(x);
  40. }
  41. jv_free(components);
  42. - jv_free(name);
  43. - return rp;
  44. + return name;
  45. }
  46. // Assumes name has been validated