config --get --path: check for unset $HOME
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20100723012322.GA27113@burratino
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20100726005111.GA29755@burratino
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 config --get --path: check for unset $HOME
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.
---
Quoted 7 lines · Julien Cristau
* 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 resultSegmentation fault
Good catch.
path.c | 2 ++ t/t1300-repo-config.sh | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletions(-)
path.c +2 -0
@@ -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);
t/t1300-repo-config.sh +23 -1
@@ -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"
Signature · 1 line
1.7.1
Quoted 6 lines · Jonathan Nieder
If $HOME is unset (as in some automated build situations), currently
git config --path path.home "~" git config --path --get path.home
Quoted 8 lines
segfaults. Error out with
Failed to expand user dir in: '~/'
instead.
Reported-by Julien Cristau <[email protected]>Signed-off-by Jonathan Nieder <[email protected]>
Thanks!
Cheers,
Julien
Quoted 8 lines · Jonathan Nieder
size_t
username_len=first_slash- username;
if (username_len== 0) {
const char *home =getenv("HOME");
+ if (!home)
+ gotoreturn_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?
Quoted 1 line · Ævar Arnfjörð Bjarmason
Should we maybe fall back on checking
pw_diringetpwuid()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
Quoted 7 lines · Jonathan Nieder
Quoted 1 line · Ęvar Arnfjörš Bjarmason
Should we maybe fall back on checking
pw_diringetpwuid()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.