Skip to content

Commit

Permalink
attr: make sure we have an xdg path before using it
Browse files Browse the repository at this point in the history
If we don't have a core.attributesfile configured, we fall
back to checking XDG config, which is usually
$HOME/.config/git/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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jul 24, 2012
1 parent 5adf84e commit f0c1c15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions t/t1306-xdg-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit f0c1c15

Please sign in to comment.