@matheusbsbs / matheus-bagliano / commits / 79bbc7fb07
Fork 0

git-remote: do not use user input in a printf format string

'git remote show' substituted the remote name into a string that was later used as a printf format string. If a remote name contains a printf format specifier like this: $ git remote add foo%sbar . then the command $ git remote show foo%sbar would print garbage (if you are lucky) or crash. This fixes it. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Sep 22, 2008 at 13:03 UTC 79bbc7fb078f8cabe04020c4619be9b571371398
1 file changed +8 -10
builtin-remote.c
+8 -10
@@ -407,14 +407,15 @@ static int rm(int argc, const char **argv)
407 return i;
408 }
409
410 -static void show_list(const char *title, struct string_list *list)
410 +static void show_list(const char *title, struct string_list *list,
411 + const char *extra_arg)
412 {
413 int i;
414
415 if (!list->nr)
416 return;
417
417 - printf(title, list->nr > 1 ? "es" : "");
418 + printf(title, list->nr > 1 ? "es" : "", extra_arg);
419 printf("\n ");
420 for (i = 0; i < list->nr; i++)
421 printf("%s%s", i ? " " : "", list->items[i].string);
@@ -477,7 +478,6 @@ static int show(int argc, const char **argv)
478
479 memset(&states, 0, sizeof(states));
480 for (; argc; argc--, argv++) {
480 - struct strbuf buf;
481 int i;
482
483 get_remote_ref_states(*argv, &states, !no_query);
@@ -503,18 +503,16 @@ static int show(int argc, const char **argv)
503 }
504
505 if (!no_query) {
506 - strbuf_init(&buf, 0);
507 - strbuf_addf(&buf, " New remote branch%%s (next fetch "
508 - "will store in remotes/%s)", states.remote->name);
509 - show_list(buf.buf, &states.new);
510 - strbuf_release(&buf);
506 + show_list(" New remote branch%s (next fetch "
507 + "will store in remotes/%s)",
508 + &states.new, states.remote->name);
509 show_list(" Stale tracking branch%s (use 'git remote "
512 - "prune')", &states.stale);
510 + "prune')", &states.stale, "");
511 }
512
513 if (no_query)
514 for_each_ref(append_ref_to_tracked_list, &states);
517 - show_list(" Tracked remote branch%s", &states.tracked);
515 + show_list(" Tracked remote branch%s", &states.tracked, "");
516
517 if (states.remote->push_refspec_nr) {
518 printf(" Local branch%s pushed with 'git push'\n ",