]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
easy_getinfo: check magic, Curl_close safety
authorStefan Eissing <stefan@eissing.org>
Wed, 10 Sep 2025 09:33:36 +0000 (11:33 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 10 Sep 2025 10:06:16 +0000 (12:06 +0200)
Check the easy handles magic in calls to curl_easy_getinfo().
In Curl_close() clear the magic after DNS shutdown since we'd
like to see tracing for this.
When clearing the magic, also clear the verbose flag so we
no longer call DEBUGFUNCTION on such a handle.

Closes #18511

lib/easy.c
lib/url.c

index b9b8d527548fdd864ba0c761063261e5cc951dac..0a4b6faf52560efa1bab99520e5b2f29a923867e 100644 (file)
@@ -877,12 +877,16 @@ void curl_easy_cleanup(CURL *ptr)
  * information from a performed transfer and similar.
  */
 #undef curl_easy_getinfo
-CURLcode curl_easy_getinfo(CURL *data, CURLINFO info, ...)
+CURLcode curl_easy_getinfo(CURL *easy, CURLINFO info, ...)
 {
+  struct Curl_easy *data = easy;
   va_list arg;
   void *paramp;
   CURLcode result;
 
+  if(!GOOD_EASY_HANDLE(data))
+    return CURLE_BAD_FUNCTION_ARGUMENT;
+
   va_start(arg, info);
   paramp = va_arg(arg, void *);
 
index b52267cb67399d3bc280c98f1f6545b176b78486..45d44bac738f6593c92098ba8681e9b11de103f8 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -258,13 +258,20 @@ CURLcode Curl_close(struct Curl_easy **datap)
 
   Curl_expire_clear(data); /* shut off any timers left */
 
-  data->magic = 0; /* force a clear AFTER the possibly enforced removal from
-                      the multi handle, since that function uses the magic
-                      field! */
-
   if(data->state.rangestringalloc)
     free(data->state.range);
 
+  /* release any resolve information this transfer kept */
+  Curl_async_destroy(data);
+  Curl_resolv_unlink(data, &data->state.dns[0]); /* done with this */
+  Curl_resolv_unlink(data, &data->state.dns[1]);
+
+  data->set.verbose = FALSE; /* no more calls to DEBUGFUNCTION */
+  data->magic = 0; /* force a clear AFTER the possibly enforced removal from
+                    * the multi handle and async dns shutdown. The multi
+                    * handle might check the magic and so might any
+                    * DEBUGFUNCTION invoked for tracing */
+
   /* freed here just in case DONE was not called */
   Curl_req_free(&data->req, data);
 
@@ -299,11 +306,6 @@ CURLcode Curl_close(struct Curl_easy **datap)
   Curl_safefree(data->info.contenttype);
   Curl_safefree(data->info.wouldredirect);
 
-  /* release any resolve information this transfer kept */
-  Curl_async_destroy(data);
-  Curl_resolv_unlink(data, &data->state.dns[0]); /* done with this */
-  Curl_resolv_unlink(data, &data->state.dns[1]);
-
   data_priority_cleanup(data);
 
   /* No longer a dirty share, if it exists */