From 763c51780c0830983ee75d66d516d65911b0e96a Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Sun, 13 Jul 2014 00:18:40 +0200 Subject: netrc: fixed thread safety problem by using getpwuid_r if available The old way using getpwuid could cause problems in programs that enable reading from netrc files simultaneously in multiple threads. Reported-by: David Woodhouse --- lib/netrc.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/netrc.c b/lib/netrc.c index a7a710159..7435d94c4 100644 --- a/lib/netrc.c +++ b/lib/netrc.c @@ -76,7 +76,19 @@ int Curl_parsenetrc(const char *host, char *home = curl_getenv("HOME"); /* portable environment reader */ if(home) { home_alloc = TRUE; -#if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID) +#if defined(HAVE_GETPWUID_R) && defined(HAVE_GETEUID) + } + else { + struct passwd pw, *pw_res; + char pwbuf[1024]; + if(!getpwuid_r(geteuid(), &pw, pwbuf, sizeof(pwbuf), &pw_res) + && pw_res) { + home = strdup(pw.pw_dir); + if(!home) + return CURLE_OUT_OF_MEMORY; + home_alloc = TRUE; + } +#elif defined(HAVE_GETPWUID) && defined(HAVE_GETEUID) } else { struct passwd *pw; -- cgit v1.2.3