Skip to content

Commit

Permalink
Merge pull request #6255 from julek-wolfssl/fix-ssl_asn1
Browse files Browse the repository at this point in the history
Add missing guards
  • Loading branch information
dgarske authored Mar 31, 2023
2 parents 753ad4c + c56e58d commit 2ad0659
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
13 changes: 5 additions & 8 deletions src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@
int wolfssl_bn_get_value(WOLFSSL_BIGNUM* bn, mp_int* mpi);
int wolfssl_bn_set_value(WOLFSSL_BIGNUM** bn, mp_int* mpi);
#endif
#if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
static int wolfssl_bn_set_neg(WOLFSSL_BIGNUM* bn, int n);
#endif

#if defined(WOLFSSL_QT)
#include <wolfssl/wolfcrypt/sha.h>
Expand Down Expand Up @@ -211,11 +208,6 @@
#define WOLFSSL_EVP_INCLUDED
#include "wolfcrypt/src/evp.c"

#ifndef OPENSSL_EXTRA_NO_ASN1
#define WOLFSSL_SSL_ASN1_INCLUDED
#include "src/ssl_asn1.c"
#endif /* OPENSSL_EXTRA_NO_ASN1 */

#if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
!defined(WOLFCRYPT_ONLY)
/* Convert shortname to NID.
Expand Down Expand Up @@ -416,6 +408,11 @@ WC_RNG* wolfssl_make_rng(WC_RNG* rng, int* local)
#define WOLFSSL_SSL_BN_INCLUDED
#include "src/ssl_bn.c"

#ifndef OPENSSL_EXTRA_NO_ASN1
#define WOLFSSL_SSL_ASN1_INCLUDED
#include "src/ssl_asn1.c"
#endif /* OPENSSL_EXTRA_NO_ASN1 */

#define WOLFSSL_PK_INCLUDED
#include "src/pk.c"

Expand Down
6 changes: 5 additions & 1 deletion src/ssl_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
* ASN1_item APIs
******************************************************************************/

#ifndef NO_ASN

#ifdef OPENSSL_EXTRA

#ifdef OPENSSL_ALL
Expand Down Expand Up @@ -2362,7 +2364,7 @@ char* wolfSSL_i2s_ASN1_STRING(WOLFSSL_v3_ext_method *method,
}
/* Handle 0 length data separately. */
else if (s->length == 0) {
ret = XMALLOC(1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
ret = (char *)XMALLOC(1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (ret != NULL) {
ret[0] = '\0';
}
Expand Down Expand Up @@ -4022,5 +4024,7 @@ void wolfSSL_ASN1_TYPE_set(WOLFSSL_ASN1_TYPE *a, int type, void *value)

#endif /* OPENSSL_ALL || WOLFSSL_WPAS */

#endif /* !NO_ASN */

#endif /* !WOLFSSL_SSL_ASN1_INCLUDED */

17 changes: 2 additions & 15 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -31228,8 +31228,6 @@ static int test_wolfSSL_a2i_ASN1_INTEGER(void)
BIO_free(out);

AssertNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1);
AssertIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
AssertIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
BIO_free(fixed);
Expand Down Expand Up @@ -31440,6 +31438,7 @@ static int test_wolfSSL_ASN1_OBJECT(void)
AssertNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
ASN1_OBJECT_free(a);
s.obj = der;
s.objSz = sizeof(der);
AssertNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
ASN1_OBJECT_free(a);
ASN1_OBJECT_free(&s);
Expand Down Expand Up @@ -32016,8 +32015,6 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void)
AssertIntEQ(p_len, 15);
BIO_read(bio, (void*)rbuf, 15);
AssertStrEQ((char*)rbuf, "Hello wolfSSL!");
AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1);
AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 14), 1);
Expand All @@ -32030,8 +32027,6 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void)
AssertIntEQ(p_len, 9);
BIO_read(bio, (void*)rbuf, 9);
AssertStrEQ((char*)rbuf, "a\\+\\;\\<\\>");
AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1);
AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 8), 1);
Expand All @@ -32044,8 +32039,6 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void)
AssertIntEQ(p_len, 28);
BIO_read(bio, (void*)rbuf, 28);
AssertStrEQ((char*)rbuf, "OCTET STRING:Hello wolfSSL!");
AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1);
AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 12), 1);
Expand All @@ -32060,8 +32053,6 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void)
AssertIntEQ(p_len, 31);
BIO_read(bio, (void*)rbuf, 31);
AssertStrEQ((char*)rbuf, "#48656C6C6F20776F6C6653534C2100");
AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1);
AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
Expand All @@ -32074,8 +32065,6 @@ static int test_wolfSSL_ASN1_STRING_print_ex(void)
AssertIntEQ(p_len, 35);
BIO_read(bio, (void*)rbuf, 35);
AssertStrEQ((char*)rbuf, "#040F48656C6C6F20776F6C6653534C2100");
AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1);
AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
AssertIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 2), 1);
Expand Down Expand Up @@ -32235,7 +32224,7 @@ static int test_wolfSSL_ASN1_GENERALIZEDTIME_print(void)
BIO_free(bio);

AssertNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
for (i = 0; i < 20; i++) {
for (i = 1; i < 20; i++) {
AssertIntEQ(BIO_set_write_buf_size(bio, i), 1);
AssertIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, &gtime), 0);
}
Expand Down Expand Up @@ -32677,8 +32666,6 @@ static int test_wolfSSL_ASN1_TIME_print(void)
AssertIntEQ(XMEMCMP(buf, "Dec 16 21:17:49 2022 GMT", sizeof(buf) - 1), 0);

/* Test BIO_write fails. */
AssertIntEQ(BIO_set_write_buf_size(fixed, 0), 1);
AssertIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
AssertIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
AssertIntEQ(BIO_set_write_buf_size(fixed, 23), 1);
Expand Down

0 comments on commit 2ad0659

Please sign in to comment.