Commit Diff


commit - f0207f6a4f16fab481f483d0db43ed50ca670e7e
commit + 0c4004e3b4aebeca63f9345737174e8fbe69abb7
blob - 89384c49f08bc3027b3bab5aea7dd94029669839
blob + 0219d3d35f26f8c729484c3c1e4243c3d1f8b97a
--- include/got_path.h
+++ include/got_path.h
@@ -101,7 +101,10 @@ const struct got_error *got_path_mkdir(const char *);
 /* Determine whether a directory has no files or directories in it. */
 int got_path_dir_is_empty(const char *);
 
-/* dirname(3) with error handling and dynamically allocated result. */
+/*
+ * dirname(3) with error handling, dynamically allocated result, and
+ * unmodified input.
+ */
 const struct got_error *got_path_dirname(char **, const char *);
 
 /*
blob - 0648aebafecc757f25710300b9e98d53c91c585a
blob + 54f8f6f973385072b6bba9a07e98cca11948d8b8
--- lib/path.c
+++ lib/path.c
@@ -358,9 +358,13 @@ got_path_dir_is_empty(const char *dir)
 const struct got_error *
 got_path_dirname(char **parent, const char *path)
 {
+	char buf[PATH_MAX];
 	char *p;
 
-	p = dirname(path);
+	if (strlcpy(buf, path, sizeof(buf)) >= sizeof(buf))
+		return got_error(GOT_ERR_NO_SPACE);
+
+	p = dirname(buf);
 	if (p == NULL)
 		return got_error_from_errno2("dirname", path);