From: Simon Josefsson Date: Wed, 3 Jun 2009 04:15:02 +0000 (+0200) Subject: Reduce stack usage. X-Git-Tag: gnutls_2_9_1~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fe0f79e5471185ff709679bb7539038f9ea28385;p=thirdparty%2Fgnutls.git Reduce stack usage. --- diff --git a/lib/x509/crq.c b/lib/x509/crq.c index fb4c6f97b1..01e8d73725 100644 --- a/lib/x509/crq.c +++ b/lib/x509/crq.c @@ -1633,8 +1633,7 @@ get_subject_alt_name (gnutls_x509_crq_t crq, int result; ASN1_TYPE c2 = ASN1_TYPE_EMPTY; gnutls_x509_subject_alt_name_t type; - opaque dnsname[2048]; - size_t dnsname_size = sizeof (dnsname); + gnutls_datum_t dnsname = { NULL, 0 }; if (crq == NULL) { @@ -1647,25 +1646,45 @@ get_subject_alt_name (gnutls_x509_crq_t crq, else *ret_size = 0; - if ((result = - gnutls_x509_crq_get_extension_by_oid (crq, "2.5.29.17", 0, - dnsname, &dnsname_size, - critical)) < 0) + /* Extract extension. + */ + result = gnutls_x509_crq_get_extension_by_oid (crq, "2.5.29.17", 0, + NULL, &dnsname.size, + critical); + if (result < 0) { gnutls_assert (); return result; } + dnsname.data = gnutls_malloc (dnsname.size); + if (dnsname.data == NULL) + { + gnutls_assert (); + return GNUTLS_E_MEMORY_ERROR; + } + + result = gnutls_x509_crq_get_extension_by_oid (crq, "2.5.29.17", 0, + dnsname.data, &dnsname.size, + critical); + if (result < 0) + { + gnutls_assert (); + gnutls_free (dnsname.data); + return result; + } + result = asn1_create_element (_gnutls_get_pkix (), "PKIX1.SubjectAltName", &c2); if (result != ASN1_SUCCESS) { gnutls_assert (); + gnutls_free (dnsname.data); return _gnutls_asn2err (result); } - result = asn1_der_decoding (&c2, dnsname, dnsname_size, NULL); - + result = asn1_der_decoding (&c2, dnsname.data, dnsname.size, NULL); + gnutls_free (dnsname.data); if (result != ASN1_SUCCESS) { gnutls_assert (); @@ -1673,12 +1692,9 @@ get_subject_alt_name (gnutls_x509_crq_t crq, return _gnutls_asn2err (result); } - result = - _gnutls_parse_general_name (c2, "", seq, ret, ret_size, ret_type, - othername_oid); - + result = _gnutls_parse_general_name (c2, "", seq, ret, ret_size, + ret_type, othername_oid); asn1_delete_structure (&c2); - if (result < 0) { return result;