* [PATCH] config --get --path: check for unset $HOME [not found] ` <20100726140756.GH12476@radis.liafa.jussieu.fr> @ 2010-07-26 15:06 ` Jonathan Nieder 2010-07-26 15:33 ` Julien Cristau 2010-07-26 16:35 ` Ævar Arnfjörð Bjarmason 0 siblings, 2 replies; 5+ messages in thread From: Jonathan Nieder @ 2010-07-26 15:06 UTC (permalink / raw) To: Julien Cristau; +Cc: Matthieu Moy, git If $HOME is unset (as in some automated build situations), currently git config --path path.home "~" git config --path --get path.home segfaults. Error out with Failed to expand user dir in: '~/' instead. Reported-by: Julien Cristau <jcristau@debian.org> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> --- Julien Cristau wrote: > * expecting success: > git config --get --path path.home > result && > git config --get --path path.normal >> result && > git config --get --path path.trailingtilde >> result && > test_cmp expect result > > Segmentation fault Good catch. path.c | 2 ++ t/t1300-repo-config.sh | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletions(-) diff --git a/path.c b/path.c index b4c8d91..6b23023 100644 --- a/path.c +++ b/path.c @@ -316,6 +316,8 @@ char *expand_user_path(const char *path) size_t username_len = first_slash - username; if (username_len == 0) { const char *home = getenv("HOME"); + if (!home) + goto return_null; strbuf_add(&user_path, home, strlen(home)); } else { struct passwd *pw = getpw_str(username, username_len); diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index f11f98c..7ddab5f 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -707,19 +707,41 @@ test_expect_success 'set --path' ' git config --path path.trailingtilde "foo~" && test_cmp expect .git/config' +if test "${HOME+set}" +then + test_set_prereq HOMEVAR +fi + cat >expect <<EOF $HOME/ /dev/null foo~ EOF -test_expect_success 'get --path' ' +test_expect_success HOMEVAR 'get --path' ' git config --get --path path.home > result && git config --get --path path.normal >> result && git config --get --path path.trailingtilde >> result && test_cmp expect result ' +cat >expect <<\EOF +/dev/null +foo~ +EOF + +test_expect_success 'get --path copes with unset $HOME' ' + ( + unset HOME; + test_must_fail git config --get --path path.home \ + >result 2>msg && + git config --get --path path.normal >>result && + git config --get --path path.trailingtilde >>result + ) && + grep "[Ff]ailed to expand.*~/" msg && + test_cmp expect result +' + rm .git/config git config quote.leading " test" -- 1.7.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] config --get --path: check for unset $HOME 2010-07-26 15:06 ` [PATCH] config --get --path: check for unset $HOME Jonathan Nieder @ 2010-07-26 15:33 ` Julien Cristau 2010-07-26 16:35 ` Ævar Arnfjörð Bjarmason 1 sibling, 0 replies; 5+ messages in thread From: Julien Cristau @ 2010-07-26 15:33 UTC (permalink / raw) To: Jonathan Nieder; +Cc: Matthieu Moy, git On Mon, Jul 26, 2010 at 10:06:51 -0500, Jonathan Nieder wrote: > If $HOME is unset (as in some automated build situations), > currently > > git config --path path.home "~" > git config --path --get path.home > > segfaults. Error out with > > Failed to expand user dir in: '~/' > > instead. > > Reported-by: Julien Cristau <jcristau@debian.org> > Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Tested-by: Julien Cristau <jcristau@debian.org> Thanks! Cheers, Julien ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] config --get --path: check for unset $HOME 2010-07-26 15:06 ` [PATCH] config --get --path: check for unset $HOME Jonathan Nieder 2010-07-26 15:33 ` Julien Cristau @ 2010-07-26 16:35 ` Ævar Arnfjörð Bjarmason 2010-07-26 17:08 ` Jonathan Nieder 1 sibling, 1 reply; 5+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2010-07-26 16:35 UTC (permalink / raw) To: Jonathan Nieder; +Cc: Julien Cristau, Matthieu Moy, git On Mon, Jul 26, 2010 at 15:06, Jonathan Nieder <jrnieder@gmail.com> wrote: > size_t username_len = first_slash - username; > if (username_len == 0) { > const char *home = getenv("HOME"); > + if (!home) > + goto return_null; > strbuf_add(&user_path, home, strlen(home)); > } else { > struct passwd *pw = getpw_str(username, username_len); Should we maybe fall back on checking pw_dir in getpwuid() if $HOME isn't set? ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] config --get --path: check for unset $HOME 2010-07-26 16:35 ` Ævar Arnfjörð Bjarmason @ 2010-07-26 17:08 ` Jonathan Nieder 2010-07-26 17:48 ` Ævar Arnfjörð Bjarmason 0 siblings, 1 reply; 5+ messages in thread From: Jonathan Nieder @ 2010-07-26 17:08 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason; +Cc: Julien Cristau, Matthieu Moy, git Ævar Arnfjörð Bjarmason wrote: > Should we maybe fall back on checking pw_dir in getpwuid() if $HOME isn't set? Maybe. Why? On Unix I suspect it is such a rare case as to not justify complicating the rules, but I do not know if it would help on other platforms. Jonathan ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] config --get --path: check for unset $HOME 2010-07-26 17:08 ` Jonathan Nieder @ 2010-07-26 17:48 ` Ævar Arnfjörð Bjarmason 0 siblings, 0 replies; 5+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2010-07-26 17:48 UTC (permalink / raw) To: Jonathan Nieder; +Cc: Julien Cristau, Matthieu Moy, git On Mon, Jul 26, 2010 at 17:08, Jonathan Nieder <jrnieder@gmail.com> wrote: > Ęvar Arnfjörš Bjarmason wrote: > >> Should we maybe fall back on checking pw_dir in getpwuid() if $HOME isn't set? > > Maybe. Why? On Unix I suspect it is such a rare case as to not > justify complicating the rules, but I do not know if it would help on > other platforms. I don't know if this is worth it, but in the Perl world this is a fairly common idiom: my $home = $ENV{HOME} || (getpwuid($<))[7]; Sometimes you're executing under some buggy wrapper that's scrubbing your environment. I recall running into this issue e.g. on some odd Solaris webserver, which was executing CGI scripts under my user, but $HOME wasn't set. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-07-26 17:49 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <20100723003456.2976.899.reportbug@dr-wily.mit.edu> [not found] ` <20100723012322.GA27113@burratino> [not found] ` <20100725085939.GA5281@radis.liafa.jussieu.fr> [not found] ` <20100726005111.GA29755@burratino> [not found] ` <20100726140756.GH12476@radis.liafa.jussieu.fr> 2010-07-26 15:06 ` [PATCH] config --get --path: check for unset $HOME Jonathan Nieder 2010-07-26 15:33 ` Julien Cristau 2010-07-26 16:35 ` Ævar Arnfjörð Bjarmason 2010-07-26 17:08 ` Jonathan Nieder 2010-07-26 17:48 ` Ævar Arnfjörð Bjarmason
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).