Commit 0a9483d0af324e2f67bb3af427577a35fb7ed401

Stefan Sperling 2020-10-19T23:14:59

handle non-const basename in got_path_basename() ok millert

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/lib/path.c b/lib/path.c
index 549cac5..0648aeb 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -424,9 +424,13 @@ done:
 const struct got_error *
 got_path_basename(char **s, const char *path)
 {
+	char buf[PATH_MAX];
 	char *base;
 
-	base = basename(path);
+	if (strlcpy(buf, path, sizeof(buf)) >= sizeof(buf))
+		return got_error(GOT_ERR_NO_SPACE);
+
+	base = basename(buf);
 	if (base == NULL)
 		return got_error_from_errno2("basename", path);