git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] builtin-config: Fix crash when using "-f <relative path>" from non-root dir

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 26, 2010, 20:02 UTC
Message-ID
<7v8wbkzlbk.fsf@alter.siamese.dyndns.org>
In-Reply-To
<201001261602.16876.johan@herland.net>
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.

Show 10 quoted lines
> 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
Previous: Johan Herland
Message 2 of 2 in “builtin-config: Fix crash when using "-f <relative path>" from non-root dir”
  1. builtin-config: Fix crash when using "-f <relative path>" from non-root dirJohan Herland, Jan 26, 2010
  2. Junio C HamanoJan 26, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.