notes_merge_commit(): do not pass temporary buffer to other function
It is unsafe to pass a temporary buffer as an argument to read_directory(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Acked-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Sep 27, 2011 at 06:46 UTC
852844561e8daaa6689cab48a725f764ad5779cb
1 file changed
+2
-1
notes-merge.c
+2
-1
@@ -680,7 +680,7 @@ int notes_merge_commit(struct notes_merge_options *o,
680
* Finally store the new commit object SHA1 into 'result_sha1'.
681
*/
682
struct dir_struct dir;
683
- const char *path = git_path(NOTES_MERGE_WORKTREE "/");
683
+ char *path = xstrdup(git_path(NOTES_MERGE_WORKTREE "/"));
684
int path_len = strlen(path), i;
685
const char *msg = strstr(partial_commit->buffer, "\n\n");
686
@@ -720,6 +720,7 @@ int notes_merge_commit(struct notes_merge_options *o,
720
result_sha1);
721
OUTPUT(o, 4, "Finalized notes merge commit: %s",
722
sha1_to_hex(result_sha1));
723
+ free(path);
724
return 0;
725
}
726