Commit 3f17dee4f66ddd410b6ab5a184e3a8c3608d3892

Stefan Sperling 2019-07-27T11:08:47

prevent array access with negative index in got_worktree_resolve_path()

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/lib/worktree.c b/lib/worktree.c
index 686a315..c15d384 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2362,7 +2362,7 @@ got_worktree_resolve_path(char **wt_path, struct got_worktree *worktree,
 
 	/* XXX status walk can't deal with trailing slash! */
 	len = strlen(path);
-	while (path[len - 1] == '/') {
+	while (len > 0 && path[len - 1] == '/') {
 		path[len - 1] = '\0';
 		len--;
 	}