diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2022-07-12 12:03:53 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2022-07-12 12:03:53 +0300 |
commit | eeebfbedb3ea4cab5c0aac178b683b7dd26b0bf6 (patch) | |
tree | 4783d362be8e22467d0f5eb581ce6f65e33acb04 /contrib/libs/curl/lib/netrc.c | |
parent | 4213b519b93b5e3d657bc362837adfea82579dcc (diff) | |
download | ydb-eeebfbedb3ea4cab5c0aac178b683b7dd26b0bf6.tar.gz |
Update contrib/libs/curl to 7.84.0
Diffstat (limited to 'contrib/libs/curl/lib/netrc.c')
-rw-r--r-- | contrib/libs/curl/lib/netrc.c | 88 |
1 files changed, 77 insertions, 11 deletions
diff --git a/contrib/libs/curl/lib/netrc.c b/contrib/libs/curl/lib/netrc.c index 0a4ae2cdca..83fe6a7e09 100644 --- a/contrib/libs/curl/lib/netrc.c +++ b/contrib/libs/curl/lib/netrc.c @@ -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 @@ -18,6 +18,8 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * + * SPDX-License-Identifier: curl + * ***************************************************************************/ #include "curl_setup.h" @@ -78,24 +80,80 @@ static int parsenetrc(const char *host, file = fopen(netrcfile, FOPEN_READTEXT); if(file) { - char *tok; - char *tok_buf; bool done = FALSE; char netrcbuffer[4096]; int netrcbuffsize = (int)sizeof(netrcbuffer); while(!done && fgets(netrcbuffer, netrcbuffsize, file)) { + char *tok; + char *tok_end; + bool quoted; if(state == MACDEF) { if((netrcbuffer[0] == '\n') || (netrcbuffer[0] == '\r')) state = NOTHING; else continue; } - tok = strtok_r(netrcbuffer, " \t\n", &tok_buf); - if(tok && *tok == '#') - /* treat an initial hash as a comment line */ - continue; + tok = netrcbuffer; while(tok) { + while(ISSPACE(*tok)) + tok++; + /* tok is first non-space letter */ + if(!*tok || (*tok == '#')) + /* end of line or the rest is a comment */ + break; + + /* leading double-quote means quoted string */ + quoted = (*tok == '\"'); + + tok_end = tok; + if(!quoted) { + while(!ISSPACE(*tok_end)) + tok_end++; + *tok_end = 0; + } + else { + bool escape = FALSE; + bool endquote = FALSE; + char *store = tok; + tok_end++; /* pass the leading quote */ + while(*tok_end) { + char s = *tok_end; + if(escape) { + escape = FALSE; + switch(s) { + case 'n': + s = '\n'; + break; + case 'r': + s = '\r'; + break; + case 't': + s = '\t'; + break; + } + } + else if(s == '\\') { + escape = TRUE; + tok_end++; + continue; + } + else if(s == '\"') { + tok_end++; /* pass the ending quote */ + endquote = TRUE; + break; + } + *store++ = s; + tok_end++; + } + *store = 0; + if(escape || !endquote) { + /* bad syntax, get out */ + retcode = NETRC_FAILED; + goto out; + } + } + if((login && *login) && (password && *password)) { done = TRUE; break; @@ -183,9 +241,8 @@ static int parsenetrc(const char *host, } break; } /* switch (state) */ - - tok = strtok_r(NULL, " \t\n", &tok_buf); - } /* while(tok) */ + tok = ++tok_end; + } } /* while fgets() */ out: @@ -235,6 +292,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 +303,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; @@ -256,6 +315,13 @@ int Curl_parsenetrc(const char *host, if(pw) { home = pw->pw_dir; } +#elif defined(_WIN32) + } + else { + homea = curl_getenv("USERPROFILE"); + if(homea) { + home = homea; + } #endif } |