From: SaltyMilk Date: Mon, 10 Jul 2023 19:43:28 +0000 (+0200) Subject: [PATCH] fopen: optimize X-Git-Tag: archive/raspbian/7.88.1-10+rpi1+deb12u5^2~9 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=01d2ad8fee6cf9b1e349e10b311485aadefd18c3;p=curl.git [PATCH] fopen: optimize Closes #11419 Gbp-Pq: Name CVE-2023-32001.patch --- diff --git a/lib/fopen.c b/lib/fopen.c index f710dbf0..8c728f2a 100644 --- a/lib/fopen.c +++ b/lib/fopen.c @@ -56,13 +56,13 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename, int fd = -1; *tempname = NULL; - if(stat(filename, &sb) == -1 || !S_ISREG(sb.st_mode)) { - /* a non-regular file, fallback to direct fopen() */ - *fh = fopen(filename, FOPEN_WRITETEXT); - if(*fh) - return CURLE_OK; + *fh = fopen(filename, FOPEN_WRITETEXT); + if(!*fh) goto fail; - } + if(fstat(fileno(*fh), &sb) == -1 || !S_ISREG(sb.st_mode)) + return CURLE_OK; + fclose(*fh); + *fh = NULL; result = Curl_rand_hex(data, randsuffix, sizeof(randsuffix)); if(result)