{"thread":{"id":"28509","subject":"[PATCH] notes_merge_commit(): do not pass temporary buffer to other function","startedAt":"2011-09-27T04:46:53Z","lastAt":"2011-09-28T03:10:25Z","messageCount":5,"participants":["Michael Haggerty","Johan Herland","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"176307","messageId":"1317098813-30839-1-git-send-email-mhagger@alum.mit.edu","threadId":"28509","inReplyTo":null,"subject":"[PATCH] notes_merge_commit(): do not pass temporary buffer to other function","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-09-27T04:46:53Z","receivedAt":"2011-09-27T04:46:53Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"It is unsafe to pass a temporary buffer as an argument to\nread_directory().\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n\nI discovered this problem when an innocent modification to unrelated\ncode triggered test failures.\n\n notes-merge.c |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git notes-merge.c notes-merge.c\nindex e1aaf43..baaf31f 100644\n--- notes-merge.c\n+++ notes-merge.c\n@@ -680,7 +680,7 @@ int notes_merge_commit(struct notes_merge_options *o,\n \t * Finally store the new commit object SHA1 into 'result_sha1'.\n \t */\n \tstruct dir_struct dir;\n-\tconst char *path = git_path(NOTES_MERGE_WORKTREE \"/\");\n+\tchar *path = xstrdup(git_path(NOTES_MERGE_WORKTREE \"/\"));\n \tint path_len = strlen(path), i;\n \tconst char *msg = strstr(partial_commit->buffer, \"\\n\\n\");\n \n@@ -720,6 +720,7 @@ int notes_merge_commit(struct notes_merge_options *o,\n \t\t\t    result_sha1);\n \tOUTPUT(o, 4, \"Finalized notes merge commit: %s\",\n \t       sha1_to_hex(result_sha1));\n+\tfree(path);\n \treturn 0;\n }\n \n-- \n1.7.7.rc2\n"},{"id":"176311","messageId":"CALKQrgcO20am0nU7W=hmbMYVjjGi0-REB8=Xko5NtXjjG4UZag@mail.gmail.com","threadId":"28509","inReplyTo":"1317098813-30839-1-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH] notes_merge_commit(): do not pass temporary buffer to other function","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2011-09-27T07:12:40Z","receivedAt":"2011-09-27T07:12:40Z","isPatch":true,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Tue, Sep 27, 2011 at 06:46, Michael Haggerty <mhagger@alum.mit.edu> wrote:\n> It is unsafe to pass a temporary buffer as an argument to\n> read_directory().\n>\n> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n\nACK.\n\n...Johan\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"176344","messageId":"7vd3elyl8t.fsf@alter.siamese.dyndns.org","threadId":"28509","inReplyTo":"1317098813-30839-1-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH] notes_merge_commit(): do not pass temporary buffer to other function","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-09-27T16:59:30Z","receivedAt":"2011-09-27T16:59:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Haggerty <mhagger@alum.mit.edu> writes:\n\n> I discovered this problem when an innocent modification to unrelated\n> code triggered test failures.\n>\n>  notes-merge.c |    3 ++-\n>  1 files changed, 2 insertions(+), 1 deletions(-)\n>\n> diff --git notes-merge.c notes-merge.c\n> index e1aaf43..baaf31f 100644\n> --- notes-merge.c\n> +++ notes-merge.c\n\nIt is Ok to play with -p0 yourself but please don't do that in the public.\n\n> @@ -680,7 +680,7 @@ int notes_merge_commit(struct notes_merge_options *o,\n>  \t * Finally store the new commit object SHA1 into 'result_sha1'.\n>  \t */\n>  \tstruct dir_struct dir;\n> -\tconst char *path = git_path(NOTES_MERGE_WORKTREE \"/\");\n> +\tchar *path = xstrdup(git_path(NOTES_MERGE_WORKTREE \"/\"));\n>  \tint path_len = strlen(path), i;\n>  \tconst char *msg = strstr(partial_commit->buffer, \"\\n\\n\");\n>  \n> @@ -720,6 +720,7 @@ int notes_merge_commit(struct notes_merge_options *o,\n>  \t\t\t    result_sha1);\n>  \tOUTPUT(o, 4, \"Finalized notes merge commit: %s\",\n>  \t       sha1_to_hex(result_sha1));\n> +\tfree(path);\n>  \treturn 0;\n>  }\n"},{"id":"176377","messageId":"4E828B6C.1010707@alum.mit.edu","threadId":"28509","inReplyTo":"7vd3elyl8t.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] notes_merge_commit(): do not pass temporary buffer to other function","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2011-09-28T02:50:20Z","receivedAt":"2011-09-28T02:50:20Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 09/27/2011 06:59 PM, Junio C Hamano wrote:\n> Michael Haggerty <mhagger@alum.mit.edu> writes:\n> \n>> I discovered this problem when an innocent modification to unrelated\n>> code triggered test failures.\n>>\n>>  notes-merge.c |    3 ++-\n>>  1 files changed, 2 insertions(+), 1 deletions(-)\n>>\n>> diff --git notes-merge.c notes-merge.c\n>> index e1aaf43..baaf31f 100644\n>> --- notes-merge.c\n>> +++ notes-merge.c\n> \n> It is Ok to play with -p0 yourself but please don't do that in the public.\n\nSorry; I had set diff.noprefix=true, not realizing that it would affect\nthings like \"git format-patch\".  It also confused emacs' magit mode, and\nprobably some other tools.  It's now set permanently back to false.\n\nThe reason I was experimenting with this option is that it is a quick\ndouble-click to select a filename like \"foo/bar\" in the diff output,\nwhereas selecting the filename out of \"a/foo/bar\" requires a slower\nclick and drag.  Once I considered whether git could be taught to\nexplicitly ignore the \"[ab]/\" prefix when parsing filenames, but that is\ntoo evil even for me :-)\n\nMichael\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\nhttp://softwareswirl.blogspot.com/\n"},{"id":"176378","messageId":"7vty7xs6ou.fsf@alter.siamese.dyndns.org","threadId":"28509","inReplyTo":"4E828B6C.1010707@alum.mit.edu","subject":"Re: [PATCH] notes_merge_commit(): do not pass temporary buffer to other function","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-09-28T03:10:25Z","receivedAt":"2011-09-28T03:10:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Haggerty <mhagger@alum.mit.edu> writes:\n\n>>> diff --git notes-merge.c notes-merge.c\n>>> index e1aaf43..baaf31f 100644\n>>> --- notes-merge.c\n>>> +++ notes-merge.c\n>> \n>> It is Ok to play with -p0 yourself but please don't do that in the public.\n>\n> Sorry; I had set diff.noprefix=true, not realizing that it would affect\n> things like \"git format-patch\".  It also confused emacs' magit mode, and\n> probably some other tools.  It's now set permanently back to false.\n\nThanks.\n\nIt is nothing catastrophic (I applied it with \"am -p0 -s3c\" just fine),\nbut everybody here sends -p1 format, so...\n"}]}