]> granicus.if.org Git - curl/commitdiff
cookie: avoid harmless use after free
authorPaul Dreik <github@pauldreik.se>
Thu, 3 Oct 2019 08:57:09 +0000 (10:57 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 3 Oct 2019 13:43:50 +0000 (15:43 +0200)
This fix removes a use after free which can be triggered by
the internal cookie fuzzer, but otherwise is probably
impossible to trigger from an ordinary application.

The following program reproduces it:

        curl_global_init(CURL_GLOBAL_DEFAULT);
        CURL*  handle=curl_easy_init();
        CookieInfo* info=Curl_cookie_init(handle,NULL,NULL,false);
        curl_easy_setopt(handle, CURLOPT_COOKIEJAR, "/dev/null");
        Curl_flush_cookies(handle, true);
        Curl_cookie_cleanup(info);
        curl_easy_cleanup(handle);
        curl_global_cleanup();

This was found through fuzzing.

Closes #4454

lib/cookie.c

index f6b52df2f4abf05c6980f461b70295c91e2dfa37..c6c4a7bdd9fad6fbbe0a00f6c0dc16ba2f927802 100644 (file)
@@ -1646,6 +1646,7 @@ void Curl_flush_cookies(struct Curl_easy *data, int cleanup)
 
   if(cleanup && (!data->share || (data->cookies != data->share->cookies))) {
     Curl_cookie_cleanup(data->cookies);
+    data->cookies = NULL;
   }
   Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
 }