{"thread":{"id":"22396","subject":"[PATCH] builtin-config: Fix crash when using \"-f <relative path>\" from non-root dir","startedAt":"2010-01-26T15:02:16Z","lastAt":"2010-01-26T20:02:23Z","messageCount":2,"participants":["Johan Herland","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"132678","messageId":"201001261602.16876.johan@herland.net","threadId":"22396","inReplyTo":null,"subject":"[PATCH] builtin-config: Fix crash when using \"-f <relative path>\" from non-root dir","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2010-01-26T15:02:16Z","receivedAt":"2010-01-26T15:02:16Z","isPatch":true,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"When your current directory is not at the root of the working tree, and you\nuse the \"-f\" option with a relative path, the current code segfaults since\nargv has already been parsed, and argv[2] is now is a NULL pointer.\nThis patch replaces the incorrect argv[2] with the variable holding the\ngiven config file name.\n\nThe bug was introduced by d64ec16... (git config: reorganize to use parseopt).\n\nSigned-off-by: Johan Herland <johan@herland.net>\n---\n\nThis is probably v1.7.0 material, and maybe even suitable for 'maint'.\nAFAICS, d64ec16... has been with us since before v1.6.3-rc0.\n\n...Johan\n\n\n builtin-config.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 2e3ef91..4bc46b1 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -358,7 +358,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t\tif (!is_absolute_path(given_config_file) && prefix)\n \t\t\tconfig_exclusive_filename = prefix_filename(prefix,\n \t\t\t\t\t\t\t\t    strlen(prefix),\n-\t\t\t\t\t\t\t\t    argv[2]);\n+\t\t\t\t\t\t\t\t    given_config_file);\n \t\telse\n \t\t\tconfig_exclusive_filename = given_config_file;\n \t}\n-- \n1.6.6.rc2.5.g49666\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"132711","messageId":"7v8wbkzlbk.fsf@alter.siamese.dyndns.org","threadId":"22396","inReplyTo":"201001261602.16876.johan@herland.net","subject":"Re: [PATCH] builtin-config: Fix crash when using \"-f <relative path>\" from non-root dir","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-26T20:02:23Z","receivedAt":"2010-01-26T20:02:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johan Herland <johan@herland.net> writes:\n\n> When your current directory is not at the root of the working tree, and you\n> use the \"-f\" option with a relative path, the current code segfaults since\n> argv has already been parsed, and argv[2] is now is a NULL pointer.\n\nStrictly speaking, the last sentence is not necessarily true.  argv[2] is\ntypically beyond the NULL pointer parseopt added to terminate the\nresulting list.  E.g. with the attached patch to t1300 (which I will\nsquash in), argv[0] is ein.bahn, argv[1] is NULL (end of argument list\nafter parseopt stripped the options from it), and argv[2] is --file.\n\n> This patch replaces the incorrect argv[2] with the variable holding the\n> given config file name.\n>\n> The bug was introduced by d64ec16 (git config: reorganize to use parseopt).\n>\n> Signed-off-by: Johan Herland <johan@herland.net>\n> ---\n>\n> This is probably v1.7.0 material, and maybe even suitable for 'maint'.\n> AFAICS, d64ec16... has been with us since before v1.6.3-rc0.\n\nYup, this is maint worthy.  Even if argv[2] happens to be non-NULL, it\ncertainly is not given_config_file at all.\n\nThanks.\n\n t/t1300-repo-config.sh |   11 +++++++++++\n 1 files changed, 11 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex 43ea283..c81ccf2 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -398,6 +398,17 @@ test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'\n test_expect_success 'alternative GIT_CONFIG (--file)' \\\n \t'git config --file other-config -l > output && cmp output expect'\n \n+test_expect_success 'refer config from subdirectory' '\n+\tmkdir x &&\n+\t(\n+\t\tcd x &&\n+\t\techo strasse >expect\n+\t\tgit config --get --file ../other-config ein.bahn >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+\n+'\n+\n GIT_CONFIG=other-config git config anwohner.park ausweis\n \n cat > expect << EOF\n"}]}