From 8540f95444275b3ca68633e51f8b144d35661e3b Mon Sep 17 00:00:00 2001 From: Harry Sintonen Date: Sun, 15 May 2022 01:58:05 +0300 Subject: [PATCH] Curl_parsenetrc: don't access local pwbuf outside of scope 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/netrc.c b/lib/netrc.c index 0a4ae2cdca..444e4eebb5 100644 --- a/lib/netrc.c +++ b/lib/netrc.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2021, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2022, Daniel Stenberg, , 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;