{"thread":{"id":"15621","subject":"[PATCH] git-remote: do not use user input in a printf format string","startedAt":"2008-09-22T11:03:25Z","lastAt":"2008-09-22T12:41:20Z","messageCount":2,"participants":["Johannes Sixt","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"91302","messageId":"1222081405-12113-1-git-send-email-johannes.sixt@telecom.at","threadId":"15621","inReplyTo":null,"subject":"[PATCH] git-remote: do not use user input in a printf format string","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2008-09-22T11:03:25Z","receivedAt":"2008-09-22T11:03:25Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"'git remote show' substituted the remote name into a string that was later\nused as a printf format string. If a remote name contains a printf format\nspecifier like this:\n\n   $ git remote add foo%sbar .\n\nthen the command\n\n   $ git remote show foo%sbar\n\nwould print garbage (if you are lucky) or crash. This fixes it.\n\nSigned-off-by: Johannes Sixt <johannes.sixt@telecom.at>\n---\n builtin-remote.c |   17 ++++++++---------\n 1 files changed, 8 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin-remote.c b/builtin-remote.c\nindex 01945a8..890a680 100644\n--- a/builtin-remote.c\n+++ b/builtin-remote.c\n@@ -407,14 +407,15 @@ static int rm(int argc, const char **argv)\n \treturn i;\n }\n \n-static void show_list(const char *title, struct string_list *list)\n+static void show_list(const char *title, struct string_list *list,\n+\t\t      const char *extra_arg)\n {\n \tint i;\n \n \tif (!list->nr)\n \t\treturn;\n \n-\tprintf(title, list->nr > 1 ? \"es\" : \"\");\n+\tprintf(title, list->nr > 1 ? \"es\" : \"\", extra_arg);\n \tprintf(\"\\n    \");\n \tfor (i = 0; i < list->nr; i++)\n \t\tprintf(\"%s%s\", i ? \" \" : \"\", list->items[i].string);\n@@ -503,18 +504,16 @@ static int show(int argc, const char **argv)\n \t\t}\n \n \t\tif (!no_query) {\n-\t\t\tstrbuf_init(&buf, 0);\n-\t\t\tstrbuf_addf(&buf, \"  New remote branch%%s (next fetch \"\n-\t\t\t\t\"will store in remotes/%s)\", states.remote->name);\n-\t\t\tshow_list(buf.buf, &states.new);\n-\t\t\tstrbuf_release(&buf);\n+\t\t\tshow_list(\"  New remote branch%s (next fetch \"\n+\t\t\t\t\"will store in remotes/%s)\",\n+\t\t\t\t&states.new, states.remote->name);\n \t\t\tshow_list(\"  Stale tracking branch%s (use 'git remote \"\n-\t\t\t\t\"prune')\", &states.stale);\n+\t\t\t\t\"prune')\", &states.stale, \"\");\n \t\t}\n \n \t\tif (no_query)\n \t\t\tfor_each_ref(append_ref_to_tracked_list, &states);\n-\t\tshow_list(\"  Tracked remote branch%s\", &states.tracked);\n+\t\tshow_list(\"  Tracked remote branch%s\", &states.tracked, \"\");\n \n \t\tif (states.remote->push_refspec_nr) {\n \t\t\tprintf(\"  Local branch%s pushed with 'git push'\\n   \",\n-- \n1.6.0.1.281.g8a3c6\n"},{"id":"91307","messageId":"alpine.DEB.1.00.0809221440590.13830@pacific.mpi-cbg.de.mpi-cbg.de","threadId":"15621","inReplyTo":"1222081405-12113-1-git-send-email-johannes.sixt@telecom.at","subject":"Re: [PATCH] git-remote: do not use user input in a printf format string","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-09-22T12:41:20Z","receivedAt":"2008-09-22T12:41:20Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 22 Sep 2008, Johannes Sixt wrote:\n\n> 'git remote show' substituted the remote name into a string that was \n> later used as a printf format string. If a remote name contains a printf \n> format specifier like this:\n> \n>    $ git remote add foo%sbar .\n> \n> then the command\n> \n>    $ git remote show foo%sbar\n> \n> would print garbage (if you are lucky) or crash. This fixes it.\n\nThanks,\nDscho\n"}]}