git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Matthieu Moy <Matthieu.Moy@imag.fr>, git@vger.kernel.org
Subject: [PATCH 2/3] attr: make sure we have an xdg path before using it
Date: Tue, 24 Jul 2012 07:53:57 -0400	[thread overview]
Message-ID: <20120724115357.GA7353@sigill.intra.peff.net> (raw)
In-Reply-To: <20120724115305.GA7328@sigill.intra.peff.net>

If we don't have a core.attributesfile configured, we fall
back to checking XDG config. This is usually
$HOME/.config/attributes. However, if $HOME is unset, then
home_config_paths will return NULL, and we end up calling
fopen(NULL).

Depending on your system, this may or may not cause the
accompanying test to fail (e.g., on Linux and glibc, the
address will go straight to open, which will return EFAULT).
However, valgrind will reliably notice the error.

Signed-off-by: Jeff King <peff@peff.net>
---
[oops, resending because I forgot to cc git@vger]

This is another instance of Matthieu's e3ebc35 (config: fix several
access(NULL) calls, 2012-07-12). I guess it wasn't caught
because of the lack of a test without HOME set (I found it
because t5541 can trigger it in a very roundabout way).

 attr.c               | 12 +++++++-----
 t/t1306-xdg-files.sh |  6 ++++++
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/attr.c b/attr.c
index aef93d8..b52efb5 100644
--- a/attr.c
+++ b/attr.c
@@ -520,11 +520,13 @@ static void bootstrap_attr_stack(void)
 		home_config_paths(NULL, &xdg_attributes_file, "attributes");
 		git_attributes_file = xdg_attributes_file;
 	}
-	elem = read_attr_from_file(git_attributes_file, 1);
-	if (elem) {
-		elem->origin = NULL;
-		elem->prev = attr_stack;
-		attr_stack = elem;
+	if (git_attributes_file) {
+		elem = read_attr_from_file(git_attributes_file, 1);
+		if (elem) {
+			elem->origin = NULL;
+			elem->prev = attr_stack;
+			attr_stack = elem;
+		}
 	}
 
 	if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
diff --git a/t/t1306-xdg-files.sh b/t/t1306-xdg-files.sh
index 3c75c3f..1569596 100755
--- a/t/t1306-xdg-files.sh
+++ b/t/t1306-xdg-files.sh
@@ -106,6 +106,12 @@ test_expect_success 'Checking attributes in the XDG attributes file' '
 	test_cmp expected actual
 '
 
+test_expect_success 'Checking XDG attributes when HOME is unset' '
+	>expected &&
+	(sane_unset HOME &&
+	 git check-attr -a f >actual) &&
+	test_cmp expected actual
+'
 
 test_expect_success 'Checking attributes in both XDG and local attributes files' '
 	echo "f -attr_f" >.gitattributes &&
-- 
1.7.11.3.4.g9f70dbb

  reply	other threads:[~2012-07-24 11:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-24 11:53 [PATCH 1/3] test-lib.sh: unset XDG_CONFIG_HOME Jeff King
2012-07-24 11:53 ` Jeff King [this message]
2012-07-24 12:26   ` [PATCH] ignore: make sure we have an xdg path before using it Matthieu Moy
2012-07-24 13:32     ` Jeff King
2012-07-24 11:54 ` [PATCH 3/3] t1306: check that XDG_CONFIG_HOME works Jeff King
2012-07-24 12:06 ` [PATCH 1/3] test-lib.sh: unset XDG_CONFIG_HOME Matthieu Moy
2012-07-24 12:27   ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120724115357.GA7353@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Matthieu.Moy@imag.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).