{"thread":{"id":"16616","subject":"[PATCH] fetch-pack: Avoid memcpy() with src==dst","startedAt":"2008-12-06T20:50:09Z","lastAt":"2008-12-08T02:47:21Z","messageCount":2,"participants":["Thomas Rast","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"97280","messageId":"1228596609-12720-1-git-send-email-trast@student.ethz.ch","threadId":"16616","inReplyTo":null,"subject":"[PATCH] fetch-pack: Avoid memcpy() with src==dst","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2008-12-06T20:50:09Z","receivedAt":"2008-12-06T20:50:09Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"memcpy() may only be used for disjoint memory areas, but when invoked\nfrom cmd_fetch_pack(), we have my_args == &args.  (The argument cannot\nbe removed entirely because transport.c invokes with its own\nvariable.)\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n\n---\n\nFound this while valgrinding too much.\n\n builtin-fetch-pack.c |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c\nindex 372bfa2..67fb80e 100644\n--- a/builtin-fetch-pack.c\n+++ b/builtin-fetch-pack.c\n@@ -780,7 +780,8 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,\n \tstruct ref *ref_cpy;\n \n \tfetch_pack_setup();\n-\tmemcpy(&args, my_args, sizeof(args));\n+\tif (&args != my_args)\n+\t\tmemcpy(&args, my_args, sizeof(args));\n \tif (args.depth > 0) {\n \t\tif (stat(git_path(\"shallow\"), &st))\n \t\t\tst.st_mtime = 0;\n-- \ntg: (7f705dc..) t/fp-memcpy-fix (depends on: origin/master)\n"},{"id":"97321","messageId":"7viqpvbcxy.fsf@gitster.siamese.dyndns.org","threadId":"16616","inReplyTo":"1228596609-12720-1-git-send-email-trast@student.ethz.ch","subject":"Re: [PATCH] fetch-pack: Avoid memcpy() with src==dst","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-12-08T02:47:21Z","receivedAt":"2008-12-08T02:47:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thomas Rast <trast@student.ethz.ch> writes:\n\n> memcpy() may only be used for disjoint memory areas, but when invoked\n> from cmd_fetch_pack(), we have my_args == &args.  (The argument cannot\n> be removed entirely because transport.c invokes with its own\n> variable.)\n\nIt makes me wonder if it might be a better fix to abolish the use of file\nscoped global \"args\" and pass a pointer to \"struct fetch_pack_args\"\nthroughout the callchain instead.\n\nIn the current code, cmd_fetch_pack() is the only caller that passes &args\nto this function, but it is not so implausible to have a future callchain\nthat makes two calls to cmd_fetch_pack(), perhaps implementing some sort\nof alias to fetch from multiple places, would horribly break without such\na fix, because cmd_fetch_pack() assumes that args is in its pristine\nstate.\n\nI'll apply this to 'maint' and merge it up, because the patch is\nindependent of the above issue.\n\nThanks.\n"}]}