From f0c1c15c41bdcdaf71c69355ac83789466820879 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 24 Jul 2012 07:53:57 -0400 Subject: attr: make sure we have an xdg path before using it 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 Signed-off-by: Junio C Hamano --- attr.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'attr.c') diff --git a/attr.c b/attr.c index aef93d896..b52efb55a 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) { -- cgit v1.2.1