* [PATCH] builtin-config: Fix crash when using "-f <relative path>" from non-root dir
@ 2010-01-26 15:02 Johan Herland
2010-01-26 20:02 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Johan Herland @ 2010-01-26 15:02 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List, Felipe Contreras
When your current directory is not at the root of the working tree, and you
use the "-f" option with a relative path, the current code segfaults since
argv has already been parsed, and argv[2] is now is a NULL pointer.
This patch replaces the incorrect argv[2] with the variable holding the
given config file name.
The bug was introduced by d64ec16... (git config: reorganize to use parseopt).
Signed-off-by: Johan Herland <johan@herland.net>
---
This is probably v1.7.0 material, and maybe even suitable for 'maint'.
AFAICS, d64ec16... has been with us since before v1.6.3-rc0.
...Johan
builtin-config.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/builtin-config.c b/builtin-config.c
index 2e3ef91..4bc46b1 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -358,7 +358,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
if (!is_absolute_path(given_config_file) && prefix)
config_exclusive_filename = prefix_filename(prefix,
strlen(prefix),
- argv[2]);
+ given_config_file);
else
config_exclusive_filename = given_config_file;
}
--
1.6.6.rc2.5.g49666
--
Johan Herland, <johan@herland.net>
www.herland.net
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] builtin-config: Fix crash when using "-f <relative path>" from non-root dir
2010-01-26 15:02 [PATCH] builtin-config: Fix crash when using "-f <relative path>" from non-root dir Johan Herland
@ 2010-01-26 20:02 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2010-01-26 20:02 UTC (permalink / raw)
To: Johan Herland; +Cc: Git Mailing List, Felipe Contreras
Johan Herland <johan@herland.net> writes:
> When your current directory is not at the root of the working tree, and you
> use the "-f" option with a relative path, the current code segfaults since
> argv has already been parsed, and argv[2] is now is a NULL pointer.
Strictly speaking, the last sentence is not necessarily true. argv[2] is
typically beyond the NULL pointer parseopt added to terminate the
resulting list. E.g. with the attached patch to t1300 (which I will
squash in), argv[0] is ein.bahn, argv[1] is NULL (end of argument list
after parseopt stripped the options from it), and argv[2] is --file.
> This patch replaces the incorrect argv[2] with the variable holding the
> given config file name.
>
> The bug was introduced by d64ec16 (git config: reorganize to use parseopt).
>
> Signed-off-by: Johan Herland <johan@herland.net>
> ---
>
> This is probably v1.7.0 material, and maybe even suitable for 'maint'.
> AFAICS, d64ec16... has been with us since before v1.6.3-rc0.
Yup, this is maint worthy. Even if argv[2] happens to be non-NULL, it
certainly is not given_config_file at all.
Thanks.
t/t1300-repo-config.sh | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 43ea283..c81ccf2 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -398,6 +398,17 @@ test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
test_expect_success 'alternative GIT_CONFIG (--file)' \
'git config --file other-config -l > output && cmp output expect'
+test_expect_success 'refer config from subdirectory' '
+ mkdir x &&
+ (
+ cd x &&
+ echo strasse >expect
+ git config --get --file ../other-config ein.bahn >actual &&
+ test_cmp expect actual
+ )
+
+'
+
GIT_CONFIG=other-config git config anwohner.park ausweis
cat > expect << EOF
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-01-26 20:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-26 15:02 [PATCH] builtin-config: Fix crash when using "-f <relative path>" from non-root dir Johan Herland
2010-01-26 20:02 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).