Commit 0c28c72d136548ac4db4422e5192ad273d5460c6

Patrick Steinhardt 2017-06-06T14:53:45

fileops: check return value of `git_path_dirname`

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
diff --git a/src/fileops.c b/src/fileops.c
index a0a2795..bda17f0 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -1155,9 +1155,13 @@ int git_futils_fsync_dir(const char *path)
 
 int git_futils_fsync_parent(const char *path)
 {
-	char *parent = git_path_dirname(path);
-	int error = git_futils_fsync_dir(parent);
+	char *parent;
+	int error;
+
+	if ((parent = git_path_dirname(path)) == NULL)
+		return -1;
 
+	error = git_futils_fsync_dir(parent);
 	git__free(parent);
 	return error;
 }