[PATCH] fopen: optimize
authorSaltyMilk <soufiane.elmelcaoui@gmail.com>
Mon, 10 Jul 2023 19:43:28 +0000 (21:43 +0200)
committerSamuel Henrique <samueloph@debian.org>
Thu, 5 Oct 2023 21:31:47 +0000 (22:31 +0100)
Closes #11419

Gbp-Pq: Name CVE-2023-32001.patch

lib/fopen.c

index f710dbf05ae1d9354e6cc83fbba353849e537c6f..8c728f2a851c2d1035c76b1313ef49eaae30ef52 100644 (file)
@@ -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)