]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
Curl_parsenetrc: don't access local pwbuf outside of scope
authorHarry Sintonen <sintonen@iki.fi>
Sat, 14 May 2022 22:58:05 +0000 (01:58 +0300)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 16 May 2022 07:56:26 +0000 (09:56 +0200)
Accessing local variables outside of the scope is forbidden and
depending on the compiler can result in the value being
overwritten. Fixed by moving the pwbuf to be in scope.

Closes #8850

lib/netrc.c

index 0a4ae2cdcaf4690a3f107c2e6377fa9308090361..444e4eebb5ea5438859363f2a264cddc57b4da70 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -235,6 +235,9 @@ int Curl_parsenetrc(const char *host,
   char *filealloc = NULL;
 
   if(!netrcfile) {
+#if defined(HAVE_GETPWUID_R) && defined(HAVE_GETEUID)
+    char pwbuf[1024];
+#endif
     char *home = NULL;
     char *homea = curl_getenv("HOME"); /* portable environment reader */
     if(homea) {
@@ -243,7 +246,6 @@ int Curl_parsenetrc(const char *host,
     }
     else {
       struct passwd pw, *pw_res;
-      char pwbuf[1024];
       if(!getpwuid_r(geteuid(), &pw, pwbuf, sizeof(pwbuf), &pw_res)
          && pw_res) {
         home = pw.pw_dir;