From fe43a662a25ab3903176575f1a7e0f8a04a9adc5 Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Fri, 26 Dec 2014 11:53:34 +0000 Subject: vtls: Use CURLcode for Curl_ssl_init_certinfo() return type The return type for this function was 0 on success and 1 on error. This was then examined by the calling functions and, in most cases, used to return CURLE_OUT_OF_MEMORY. Instead use CURLcode for the return type and return the out of memory error directly, propagating it up the call stack. --- lib/vtls/gskit.c | 6 ++++-- lib/vtls/openssl.c | 7 +++++-- lib/vtls/vtls.c | 15 +++++++-------- lib/vtls/vtls.h | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) (limited to 'lib/vtls') diff --git a/lib/vtls/gskit.c b/lib/vtls/gskit.c index 87086de30..0d133107b 100644 --- a/lib/vtls/gskit.c +++ b/lib/vtls/gskit.c @@ -855,8 +855,10 @@ static CURLcode gskit_connect_step3(struct connectdata *conn, int sockindex) However the server certificate may be available, thus we can return info about it. */ if(data->set.ssl.certinfo) { - if(Curl_ssl_init_certinfo(data, 1)) - return CURLE_OUT_OF_MEMORY; + result = Curl_ssl_init_certinfo(data, 1); + if(result) + return result; + if(cert) { result = Curl_extract_certinfo(conn, 0, cert, certend); if(result) diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index f0127a27e..a41447a5b 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -2241,6 +2241,7 @@ static CURLcode get_cert_chain(struct connectdata *conn, struct ssl_connect_data *connssl) { + CURLcode result; STACK_OF(X509) *sk; int i; char *bufp; @@ -2258,9 +2259,11 @@ static CURLcode get_cert_chain(struct connectdata *conn, } numcerts = sk_X509_num(sk); - if(Curl_ssl_init_certinfo(data, numcerts)) { + + result = Curl_ssl_init_certinfo(data, numcerts); + if(result) { free(bufp); - return CURLE_OUT_OF_MEMORY; + return result; } infof(data, "--- Certificate chain\n"); diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c index 905ddd3e9..165f49b8b 100644 --- a/lib/vtls/vtls.c +++ b/lib/vtls/vtls.c @@ -605,22 +605,21 @@ void Curl_ssl_free_certinfo(struct SessionHandle *data) } } -int Curl_ssl_init_certinfo(struct SessionHandle * data, - int num) +CURLcode Curl_ssl_init_certinfo(struct SessionHandle *data, int num) { - struct curl_certinfo * ci = &data->info.certs; - struct curl_slist * * table; + struct curl_certinfo *ci = &data->info.certs; + struct curl_slist **table; - /* Initialize the certificate information structures. Return 0 if OK, else 1. - */ + /* Initialize the certificate information structures */ Curl_ssl_free_certinfo(data); ci->num_of_certs = num; table = calloc((size_t) num, sizeof(struct curl_slist *)); if(!table) - return 1; + return CURLE_OUT_OF_MEMORY; ci->certinfo = table; - return 0; + + return CURLE_OK; } /* diff --git a/lib/vtls/vtls.h b/lib/vtls/vtls.h index 8091868c8..19ef1cd6e 100644 --- a/lib/vtls/vtls.h +++ b/lib/vtls/vtls.h @@ -82,7 +82,7 @@ int Curl_ssl_check_cxn(struct connectdata *conn); /* Certificate information list handling. */ void Curl_ssl_free_certinfo(struct SessionHandle *data); -int Curl_ssl_init_certinfo(struct SessionHandle * data, int num); +CURLcode Curl_ssl_init_certinfo(struct SessionHandle * data, int num); CURLcode Curl_ssl_push_certinfo_len(struct SessionHandle * data, int certnum, const char * label, const char * value, size_t valuelen); -- cgit v1.2.3