Commit 455de7fa2c4ca7bb8c24c144e14c235f8d757503

Theo Buehler 2020-01-12T19:41:31

Avoid out of bounds access if path is "/". From Martin <openbsd () academicsolutions ! ch> with tweaks by me. ok stsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
diff --git a/Makefile b/Makefile
old mode 100640
new mode 100644
diff --git a/lib/path.c b/lib/path.c
index fefe29c..612f8ea 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -391,9 +391,10 @@ got_path_basename(char **s, const char *path)
 void
 got_path_strip_trailing_slashes(char *path)
 {
-	int x;
+	size_t x;
 
-	while (path[x = strlen(path) - 1] == '/')
+	x = strlen(path);
+	while (x-- > 0 && path[x] == '/')
 		path[x] = '\0';
 }