Skip to content

Commit

Permalink
Avoid user.Current if possible to avoid glibc bug
Browse files Browse the repository at this point in the history
Attempt to use `$HOME` to find the user's home directory to avoid calling
`user.Current`, which can runtime panic due to a known glib bug. This emulates
the fix in https://go-review.googlesource.com/c/oauth2/+/34175, to work around
http://golang.org/issue/13470
  • Loading branch information
Rami Chowdhury committed Oct 18, 2017
1 parent 017e4c1 commit 8081c7d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,16 @@ func (cn *conn) handlePgpass(o values) {
if filename == "" {
// XXX this code doesn't work on Windows where the default filename is
// XXX %APPDATA%\postgresql\pgpass.conf
user, err := user.Current()
if err != nil {
return
// Prefer $HOME over user.Current due to glibc bug: golang.org/issue/13470
userHome := os.Getenv("HOME")
if userHome == "" {
user, err := user.Current()
if err != nil {
return
}
userHome = user.HomeDir
}
filename = filepath.Join(user.HomeDir, ".pgpass")
filename = filepath.Join(userHome, ".pgpass")
}
fileinfo, err := os.Stat(filename)
if err != nil {
Expand Down

0 comments on commit 8081c7d

Please sign in to comment.