]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
vtls: Don't set cert info count until memory allocation is successful
authorSteve Holme <steve_holme@hotmail.com>
Fri, 26 Dec 2014 11:58:17 +0000 (11:58 +0000)
committerSteve Holme <steve_holme@hotmail.com>
Fri, 26 Dec 2014 13:11:43 +0000 (13:11 +0000)
Otherwise Curl_ssl_init_certinfo() can fail and set the num_of_certs
member variable to the requested count, which could then be used
incorrectly as libcurl closes down.

lib/vtls/vtls.c

index 165f49b8bf645cb08f33feccf29f8d3647f6d8b1..a53ff4ad6f2a78fc06b717dddb81630d7befa12b 100644 (file)
@@ -593,12 +593,14 @@ void Curl_ssl_free_certinfo(struct SessionHandle *data)
 {
   int i;
   struct curl_certinfo *ci = &data->info.certs;
+
   if(ci->num_of_certs) {
     /* free all individual lists used */
     for(i=0; i<ci->num_of_certs; i++) {
       curl_slist_free_all(ci->certinfo[i]);
       ci->certinfo[i] = NULL;
     }
+
     free(ci->certinfo); /* free the actual array too */
     ci->certinfo = NULL;
     ci->num_of_certs = 0;
@@ -610,13 +612,15 @@ CURLcode Curl_ssl_init_certinfo(struct SessionHandle *data, int num)
   struct curl_certinfo *ci = &data->info.certs;
   struct curl_slist **table;
 
-  /* Initialize the certificate information structures */
+  /* Free any previous certificate information structures */
   Curl_ssl_free_certinfo(data);
-  ci->num_of_certs = num;
+
+  /* Allocate the required certificate information structures */
   table = calloc((size_t) num, sizeof(struct curl_slist *));
   if(!table)
     return CURLE_OUT_OF_MEMORY;
 
+  ci->num_of_certs = num;
   ci->certinfo = table;
 
   return CURLE_OK;