Commit e2af0fd164e80777a70ea292bb5871329a0f8cd2

Stefan Sperling 2019-08-09T01:13:13

prevent silly use-after-free with root cause in collect_commit_logmsg()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
diff --git a/got/got.c b/got/got.c
index 2d491b8..0476470 100644
--- a/got/got.c
+++ b/got/got.c
@@ -3419,8 +3419,11 @@ collect_commit_logmsg(struct got_pathlist_head *commitable_paths, char **logmsg,
 
 	err = edit_logmsg(logmsg, a->editor, a->logmsg_path, initial_content);
 done:
-	unlink(a->logmsg_path);
-	free(a->logmsg_path);
+	if (err == NULL || err->code == GOT_ERR_COMMIT_MSG_EMPTY) {
+		unlink(a->logmsg_path);
+		free(a->logmsg_path);
+		a->logmsg_path = NULL;
+	}
 	free(initial_content);
 	free(template);