Avoid a crash if getpwuid does not work, when querying the user's full name.

This commit is contained in:
Joey Hess 2016-06-08 13:48:03 -04:00
parent 88c85ae609
commit d62d81ee1c
Failed to extract signature
3 changed files with 32 additions and 1 deletions

View file

@ -22,6 +22,8 @@ git-annex (6.20160528) UNRELEASED; urgency=medium
drop content from disk before writing location log.
* Fix bad automatic merge conflict resolution between an annexed file
and a directory with the same name when in an adjusted branch.
* Avoid a crash if getpwuid does not work, when querying the user's full
name.
-- Joey Hess <id@joeyh.name> Fri, 27 May 2016 13:12:48 -0400

View file

@ -15,6 +15,7 @@ module Utility.UserInfo (
) where
import Utility.Env
import Utility.Exception
import System.PosixCompat
import Control.Applicative
@ -47,7 +48,7 @@ myUserGecos :: IO (Maybe String)
#if defined(__ANDROID__) || defined(mingw32_HOST_OS)
myUserGecos = return Nothing
#else
myUserGecos = Just <$> myVal [] userGecos
myUserGecos = catchMaybeIO $ myVal [] userGecos
#endif
myVal :: [String] -> (UserEntry -> String) -> IO String

View file

@ -0,0 +1,28 @@
[[!comment format=mdwn
username="joey"
subject="""comment 1"""
date="2016-06-08T17:31:41Z"
content="""
IIRC it's supposed to be possible to configure a system such as LDAP
so that `getpwuid` queries it, instead of failing as it seems to on your
system, using `/etc/nsswitch.conf`. But I'm not sure about that or how to
do it and you'd need to be the admin of the system.
git-annex has three calls to `getpwuid` (aka getUserEntryForID`).
In two of them it first looks at commonly set environment variables
(HOME and USER/LOGNAME) and only uses `getpwuid` as a fallback.
It seems reasonable to crash when git-annex can't determine the user's home
directory or username in code that needs it, especially since all three
environment variables are almost always going to be set.
The third use is a GECOS lookup, and here there's no corresponding
environment variable and git-annex can deal without knowing the full name
of the user. So, I've made that not crash if `getpwuid` fails.
(There's also a little-used code path where `getpwnam` is used
to expand `~` in a git remote path. Seems best to leave this crashing
too if used on a system that does not have a working `getpwnam`.)
So, you can try upgrading to an autobuild that has the fix, and if it still
crashes, check that HOME and USER are set.
"""]]