From: Nikos Mavrogiannopoulos Date: Sat, 15 Feb 2003 17:13:07 +0000 (+0000) Subject: Null, as the data value, is now an acceptable value in functions that may return... X-Git-Tag: gnutls_0_8_3~31 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aaffc8c62d547fac81d5fa0d65021bcf1e2bae31;p=thirdparty%2Fgnutls.git Null, as the data value, is now an acceptable value in functions that may return the size of the data. --- diff --git a/lib/gnutls_ui.c b/lib/gnutls_ui.c index 4515a6971a..8a36d11d70 100644 --- a/lib/gnutls_ui.c +++ b/lib/gnutls_ui.c @@ -269,7 +269,7 @@ int gnutls_certificate_client_get_request_status(gnutls_session session) * gnutls_fingerprint - This function calculates the fingerprint of the given data * @algo: is a digest algorithm * @data: is the data - * @result: is the place where the result will be copied. + * @result: is the place where the result will be copied (may be null). * @result_size: should hold the size of the result. The actual size * of the returned result will also be copied there. * @@ -297,13 +297,15 @@ int gnutls_fingerprint(gnutls_digest_algorithm algo, const gnutls_datum* data, c return GNUTLS_E_SHORT_MEMORY_BUFFER; } *result_size = hash_len; + + if (result) { + td = _gnutls_hash_init( algo); + if (td==NULL) return GNUTLS_E_HASH_FAILED; - td = _gnutls_hash_init( algo); - if (td==NULL) return GNUTLS_E_HASH_FAILED; - - _gnutls_hash( td, data->data, data->size); + _gnutls_hash( td, data->data, data->size); - _gnutls_hash_deinit( td, result); + _gnutls_hash_deinit( td, result); + } return 0; } diff --git a/lib/x509/dn.c b/lib/x509/dn.c index 47fbca4416..a9ae049ea9 100644 --- a/lib/x509/dn.c +++ b/lib/x509/dn.c @@ -455,8 +455,11 @@ int _gnutls_x509_parse_dn_oid(ASN1_TYPE asn1_struct, GNUTLS_E_SHORT_MEMORY_BUFFER; } *sizeof_buf = size; /* -1 for the null +1 for the '#' */ - strcpy(buf, "#"); - strcat(buf, res); + + if (buf) { + strcpy(buf, "#"); + strcat(buf, res); + } return 0; } else { diff --git a/lib/x509/pkcs7.c b/lib/x509/pkcs7.c index 75df9d9687..ccce9af543 100644 --- a/lib/x509/pkcs7.c +++ b/lib/x509/pkcs7.c @@ -151,7 +151,7 @@ int gnutls_pkcs7_import(gnutls_pkcs7 pkcs7, const gnutls_datum * data, * **/ int gnutls_pkcs7_get_certificate(gnutls_pkcs7 pkcs7, - int indx, char* certificate, int* certificate_size) + int indx, unsigned char* certificate, int* certificate_size) { ASN1_TYPE c2 = ASN1_TYPE_EMPTY; int result, len; @@ -260,14 +260,15 @@ int gnutls_pkcs7_get_certificate(gnutls_pkcs7 pkcs7, end = end-start+1; - if (certificate!=NULL && end <= *certificate_size) - memcpy( certificate, &tmp[start], end); - else { + if ( end > *certificate_size) { *certificate_size = end; result = GNUTLS_E_SHORT_MEMORY_BUFFER; goto cleanup; } + if (certificate) + memcpy( certificate, &tmp[start], end); + *certificate_size = end; result = 0; diff --git a/lib/x509/pkcs7.h b/lib/x509/pkcs7.h index e3ad0b817f..2099cae8b8 100644 --- a/lib/x509/pkcs7.h +++ b/lib/x509/pkcs7.h @@ -10,5 +10,5 @@ void gnutls_pkcs7_deinit(gnutls_pkcs7 pkcs7); int gnutls_pkcs7_import(gnutls_pkcs7 pkcs7, const gnutls_datum * data, gnutls_x509_crt_fmt format); int gnutls_pkcs7_get_certificate(gnutls_pkcs7 pkcs7, - int indx, char* certificate, int* certificate_size); + int indx, unsigned char* certificate, int* certificate_size); int gnutls_pkcs7_get_certificate_count(gnutls_pkcs7 pkcs7); diff --git a/lib/x509/x509.c b/lib/x509/x509.c index d4bdfb7e89..e208a02e9d 100644 --- a/lib/x509/x509.c +++ b/lib/x509/x509.c @@ -776,7 +776,9 @@ int gnutls_x509_crt_get_extension_by_oid(gnutls_x509_crt cert, const char* oid, } *sizeof_buf = output.size; - memcpy( buf, output.data, output.size); + + if (buf) + memcpy( buf, output.data, output.size); _gnutls_free_datum( &output); @@ -999,5 +1001,6 @@ gnutls_datum tmp; tmp.data = cert_buf; tmp.size = cert_buf_size; + return gnutls_fingerprint( algo, &tmp, buf, sizeof_buf); }