]> granicus.if.org Git - curl/commitdiff
netrc: fixed thread safety problem by using getpwuid_r if available
authorDan Fandrich <dan@coneharvesters.com>
Sat, 12 Jul 2014 22:18:40 +0000 (00:18 +0200)
committerDan Fandrich <dan@coneharvesters.com>
Sat, 12 Jul 2014 22:27:22 +0000 (00:27 +0200)
The old way using getpwuid could cause problems in programs that enable
reading from netrc files simultaneously in multiple threads.

Reported-by: David Woodhouse
RELEASE-NOTES
configure.ac
lib/netrc.c

index 307568825f3e6eb16538080aab1853ca25ad8e1a..5d7936b6ede51930c56b93a8662ede7a04aca3b7 100644 (file)
@@ -58,6 +58,7 @@ This release includes the following bugfixes:
  o build: Fixed overridden compiler PDB settings in VC7 to VC12
  o ntlm_wb: Fixed buffer size not being large enough for NTLMv2 sessions [11]
  o netrc: don't abort if home dir cannot be found
+ o netrc: fixed thread safety problem by using getpwuid_r if available
 
 This release includes the following known bugs:
 
index a06f0fd1fba68c0559b1e53127ea7c0997099779..e8d322a02a0fdbc964fd3d7b208a3caf760c2bbe 100644 (file)
@@ -3033,6 +3033,7 @@ AC_CHECK_FUNCS([fork \
   getppid \
   getprotobyname \
   getpwuid \
+  getpwuid_r \
   getrlimit \
   gettimeofday \
   if_nametoindex \
index a7a710159592a8fd1b1627db6c0d737d11b1c0bb..7435d94c482811b520197f8688656da8235e2d15 100644 (file)
@@ -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;