aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-01-11 14:26:43 +0000
committerOmar Polo <op@omarpolo.com>2021-01-11 14:26:43 +0000
commit6a9ae707737d978bccbabdc36beae509151a7be2 (patch)
tree25811c637d93c4990d8a20fdbcd4c3af0fb15314
parent3c1cf9d07cb679ba444566159538b510902f2de9 (diff)
remove infinite loop
-rw-r--r--iri.c4
-rw-r--r--iri_test.c4
2 files changed, 6 insertions, 2 deletions
diff --git a/iri.c b/iri.c
index 8c02039..1901dac 100644
--- a/iri.c
+++ b/iri.c
@@ -209,8 +209,8 @@ path_clean(char *path)
/* 2. eliminate each . path name element */
for (i = path; *i; ++i) {
- if ((i == path || *i == '/') && *(i+1) == '.' &&
- *(i+2) == '/') {
+ if ((i == path || *i == '/') &&
+ *i != '.' && i[1] == '.' && i[2] == '/') {
/* move also the \0 */
memmove(i, i+2, strlen(i)-1);
i--;
diff --git a/iri_test.c b/iri_test.c
index 6200cb7..18a1020 100644
--- a/iri_test.c
+++ b/iri_test.c
@@ -153,6 +153,10 @@ main(void)
FAIL,
empty,
"reject paths that would escape the root");
+ TEST("gemini://omarpolo.com/foo/../../",
+ FAIL,
+ empty,
+ "reject paths that would escape the root")
TEST("gemini://omarpolo.com/foo/../foo/../././/bar/baz/.././.././/",
PASS,
IRI("gemini", "omarpolo.com", "", "", "", ""),