diff --git a/src/x509.c b/src/x509.c index ad8c5c08d..629d04dbb 100644 --- a/src/x509.c +++ b/src/x509.c @@ -4860,7 +4860,9 @@ void wolfSSL_GENERAL_NAME_set0_value(WOLFSSL_GENERAL_NAME *a, int type, wolfSSL_GENERAL_NAME_type_free(a); a->type = type; - a->d.dNSName = value; + if (type == GEN_DNS) { + a->d.dNSName = value; + } } /* Frees GENERAL_NAME objects. diff --git a/tests/api.c b/tests/api.c index e7cf92fdb..18970933f 100644 --- a/tests/api.c +++ b/tests/api.c @@ -41889,6 +41889,7 @@ static int test_wolfSSL_GENERAL_NAME_print(void) X509_EXTENSION* ext = NULL; AUTHORITY_INFO_ACCESS* aia = NULL; ACCESS_DESCRIPTION* ad = NULL; + ASN1_IA5STRING *dnsname = NULL; const unsigned char v4Addr[] = {192,168,53,1}; const unsigned char v6Addr[] = @@ -41943,6 +41944,17 @@ static int test_wolfSSL_GENERAL_NAME_print(void) X509_free(x509); x509 = NULL; + /* Lets test for setting as well. */ + ExpectNotNull(gn = GENERAL_NAME_new()); + ExpectNotNull(dnsname = ASN1_IA5STRING_new()); + ExpectIntEQ(ASN1_STRING_set(dnsname, "example.com", -1), 1); + GENERAL_NAME_set0_value(gn, GEN_DNS, dnsname); + dnsname = NULL; + ExpectIntEQ(GENERAL_NAME_print(out, gn), 1); + XMEMSET(outbuf, 0, sizeof(outbuf)); + ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0); + ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0); + /* test for GEN_URI */ ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);