Skip to content

Commit 6975b79

Browse files
committed
More configuration fixes
1 parent dba7aff commit 6975b79

7 files changed

Lines changed: 113 additions & 62 deletions

File tree

tests/api.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4265,8 +4265,16 @@ static int test_wolfSSL_crl_ocsp_object_api(void)
42654265
ExpectIntEQ(wolfSSL_EnableOCSP(clientSsl, WOLFSSL_OCSP_NO_NONCE),
42664266
WOLFSSL_SUCCESS);
42674267
ExpectIntEQ(wolfSSL_DisableOCSP(clientSsl), WOLFSSL_SUCCESS);
4268+
#if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
4269+
defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
42684270
ExpectIntEQ(wolfSSL_EnableOCSPStapling(clientSsl), WOLFSSL_SUCCESS);
42694271
ExpectIntEQ(wolfSSL_DisableOCSPStapling(clientSsl), WOLFSSL_SUCCESS);
4272+
#else
4273+
ExpectIntEQ(wolfSSL_EnableOCSPStapling(clientSsl),
4274+
WC_NO_ERR_TRACE(NOT_COMPILED_IN));
4275+
ExpectIntEQ(wolfSSL_DisableOCSPStapling(clientSsl),
4276+
WC_NO_ERR_TRACE(NOT_COMPILED_IN));
4277+
#endif
42704278
ExpectIntEQ(wolfSSL_SetOCSP_OverrideURL(clientSsl, "http://dummy.test"),
42714279
WOLFSSL_SUCCESS);
42724280
ExpectIntEQ(wolfSSL_SetOCSP_OverrideURL(clientSsl, ""), WOLFSSL_SUCCESS);

tests/api/test_asn.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,7 +2323,10 @@ int test_wc_AsnPkcs8Coverage(void)
23232323
ret == WC_NO_ERR_TRACE(ASN_INPUT_E));
23242324
/* One byte too small triggers BAD_FUNC_ARG. */
23252325
if (encSz > 0) {
2326-
byte* tooSmall = (byte*)XMALLOC(encSz - 1, NULL,
2326+
/* Allocate full encSz bytes so the buffer is not overrun;
2327+
* pass smallSz = encSz-1 so the library's bounds check fires
2328+
* before any write occurs. */
2329+
byte* tooSmall = (byte*)XMALLOC(encSz, NULL,
23272330
DYNAMIC_TYPE_TMP_BUFFER);
23282331
word32 smallSz = encSz - 1;
23292332
ExpectNotNull(tooSmall);
@@ -2367,7 +2370,9 @@ int test_wc_AsnPkcs8Coverage(void)
23672370
/* Too-small buffer after knowing real size. */
23682371
{
23692372
word32 smallSz = sz - 1;
2370-
byte* small2 = (byte*)XMALLOC(smallSz, NULL,
2373+
/* Allocate full sz bytes to avoid buffer overrun;
2374+
* smallSz < sz triggers the library's bounds check. */
2375+
byte* small2 = (byte*)XMALLOC(sz, NULL,
23712376
DYNAMIC_TYPE_TMP_BUFFER);
23722377
if (small2 != NULL) {
23732378
int ret = wc_EncryptPKCS8Key(pkcs8Buf, pkcs8Sz,

tests/api/test_ecc.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3498,19 +3498,24 @@ int test_wc_EccBadArgCoverage7(void)
34983498
sigLen = (word32)sizeof(sig);
34993499
ExpectIntEQ(wc_ecc_rs_to_sig(validR, validS, sig, &sigLen), 0);
35003500

3501-
/* r is negative: mp_isneg(rtmp)==MP_YES → MP_READ_E.
3502-
* The s is non-zero (validS), so mp_iszero check passes first.
3503-
* This makes the first OR-operand at L11487 true. */
3504-
sigLen = (word32)sizeof(sig);
3505-
ExpectIntEQ(wc_ecc_rs_to_sig(negHex, validS, sig, &sigLen),
3506-
WC_NO_ERR_TRACE(MP_READ_E));
3507-
3508-
/* s is negative: mp_isneg(stmp)==MP_YES → MP_READ_E.
3509-
* r is validR (positive non-zero), so the first operand is false
3510-
* and we isolate the second operand of the OR. */
3511-
sigLen = (word32)sizeof(sig);
3512-
ExpectIntEQ(wc_ecc_rs_to_sig(validR, negHex, sig, &sigLen),
3513-
WC_NO_ERR_TRACE(MP_READ_E));
3501+
/* r is negative: the library rejects the negative value. In
3502+
* integer/heap math this happens via the explicit mp_isneg check
3503+
* inside wc_ecc_rs_to_sig (→ MP_READ_E). In sp_int the leading '-'
3504+
* is rejected earlier by sp_read_radix (→ MP_VAL). Either fail
3505+
* result is acceptable. */
3506+
{
3507+
int r;
3508+
sigLen = (word32)sizeof(sig);
3509+
r = wc_ecc_rs_to_sig(negHex, validS, sig, &sigLen);
3510+
ExpectTrue(r == WC_NO_ERR_TRACE(MP_READ_E) ||
3511+
r == WC_NO_ERR_TRACE(MP_VAL));
3512+
3513+
/* s is negative: same reasoning applies to the second operand. */
3514+
sigLen = (word32)sizeof(sig);
3515+
r = wc_ecc_rs_to_sig(validR, negHex, sig, &sigLen);
3516+
ExpectTrue(r == WC_NO_ERR_TRACE(MP_READ_E) ||
3517+
r == WC_NO_ERR_TRACE(MP_VAL));
3518+
}
35143519
}
35153520

35163521
#endif /* HAVE_ECC && !NO_ECC256 && !NO_ECC_SECP && !WC_NO_RNG &&

tests/api/test_evp_cipher.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,7 +2971,8 @@ int test_wolfSSL_EvpCipherCtxCtrlAead(void)
29712971
EVP_CIPHER_CTX *ctx = NULL;
29722972
EVP_CIPHER_CTX *ctx_nb = NULL; /* non-AEAD context */
29732973
byte key[16];
2974-
byte iv[12];
2974+
/* Sized for AES-CBC (16 bytes); AES-GCM only reads the first 12. */
2975+
byte iv[16];
29752976
byte tag[16];
29762977
byte tagbuf[16];
29772978
XMEMSET(key, 0xAB, sizeof(key));
@@ -3707,13 +3708,16 @@ int test_wolfSSL_EvpCipherInitBatch4(void)
37073708
((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
37083709
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)))
37093710
{
3710-
byte iv12[12];
3711-
XMEMSET(iv12, 0x44, sizeof(iv12));
3711+
/* Sized for AES block (16); wolfSSL_EVP_CipherInit -> wc_AesSetIV
3712+
* reads a full AES_BLOCK_SIZE even when the logical GCM nonce is
3713+
* 12 bytes. */
3714+
byte iv16gcm[16];
3715+
XMEMSET(iv16gcm, 0x44, sizeof(iv16gcm));
37123716
/* Passing a new cipher type on an already-initialised ctx resets
37133717
* the type (L7215 branch: type != NULL → full re-init).
37143718
* May succeed or fail depending on whether AES GCM low-level was
37153719
* already inited; just drive the branch. */
3716-
(void)EVP_CipherInit(ctx, EVP_aes_128_gcm(), key128, iv12, 1);
3720+
(void)EVP_CipherInit(ctx, EVP_aes_128_gcm(), key128, iv16gcm, 1);
37173721
}
37183722
#endif /* HAVE_AESGCM ... */
37193723

tests/api/test_pkcs7.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ int test_wc_PKCS7_EncodeSignedData_ex(void)
12281228
int certSz;
12291229
int keySz;
12301230

1231-
ExpectTure((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
1231+
ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
12321232
XBADFILE);
12331233
ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof(cert), fp), 0);
12341234
if (fp != XBADFILE) {

tests/api/test_tls.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ int test_utils_memio_move_message(void)
3939
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
4040
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
4141
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
42+
struct test_memio_ctx test_ctx;
4243
(void)ctx_c;
4344
(void)ssl_c;
4445
(void)ctx_s;
4546
(void)ssl_s;
46-
struct test_memio_ctx test_ctx;
4747
(void)test_ctx;
4848

4949
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
@@ -193,11 +193,11 @@ int test_tls12_curve_intersection(void) {
193193
defined(HAVE_CURVE25519)
194194
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
195195
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
196+
struct test_memio_ctx test_ctx;
196197
(void)ctx_c;
197198
(void)ssl_c;
198199
(void)ctx_s;
199200
(void)ssl_s;
200-
struct test_memio_ctx test_ctx;
201201
(void)test_ctx;
202202
int ret;
203203
const char* curve_name;
@@ -281,11 +281,11 @@ int test_tls13_curve_intersection(void) {
281281
defined(WOLFSSL_TLS13) && defined(HAVE_ECC) && defined(HAVE_CURVE25519)
282282
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
283283
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
284+
struct test_memio_ctx test_ctx;
284285
(void)ctx_c;
285286
(void)ssl_c;
286287
(void)ctx_s;
287288
(void)ssl_s;
288-
struct test_memio_ctx test_ctx;
289289
(void)test_ctx;
290290
const char* curve_name;
291291
int test1[] ={WOLFSSL_ECC_SECP256R1};
@@ -323,11 +323,11 @@ int test_tls_certreq_order(void)
323323
*/
324324
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
325325
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
326+
struct test_memio_ctx test_ctx;
326327
(void)ctx_c;
327328
(void)ssl_c;
328329
(void)ctx_s;
329330
(void)ssl_s;
330-
struct test_memio_ctx test_ctx;
331331
(void)test_ctx;
332332
int i = 0;
333333
const char* msg = NULL;
@@ -1111,11 +1111,11 @@ int test_tls_tlsx_sni_options_coverage(void)
11111111
!defined(WOLFSSL_NO_TLS12) && defined(HAVE_SNI)
11121112
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
11131113
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
1114+
struct test_memio_ctx test_ctx;
11141115
(void)ctx_c;
11151116
(void)ssl_c;
11161117
(void)ctx_s;
11171118
(void)ssl_s;
1118-
struct test_memio_ctx test_ctx;
11191119
(void)test_ctx;
11201120

11211121
/* --- Subtest 1: client sends "example.com", server expects "example.com"
@@ -1226,11 +1226,11 @@ int test_tls_tlsx_sc_parse_coverage(void)
12261226
!defined(NO_WOLFSSL_CLIENT)
12271227
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
12281228
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
1229+
struct test_memio_ctx test_ctx;
12291230
(void)ctx_c;
12301231
(void)ssl_c;
12311232
(void)ctx_s;
12321233
(void)ssl_s;
1233-
struct test_memio_ctx test_ctx;
12341234
(void)test_ctx;
12351235

12361236
/* --- Subtest 1: normal curve intersection (extension != NULL path,
@@ -1323,11 +1323,11 @@ int test_tls_tlsx_sv_parse_coverage(void)
13231323
defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12)
13241324
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
13251325
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
1326+
struct test_memio_ctx test_ctx;
13261327
(void)ctx_c;
13271328
(void)ssl_c;
13281329
(void)ctx_s;
13291330
(void)ssl_s;
1330-
struct test_memio_ctx test_ctx;
13311331
(void)test_ctx;
13321332

13331333
/* --- Subtest 1: pure TLS 1.3 handshake.
@@ -1454,11 +1454,11 @@ int test_tls_build_handshake_hash_coverage(void)
14541454
!defined(WOLFSSL_NO_TLS12) && !defined(NO_RSA)
14551455
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
14561456
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
1457+
struct test_memio_ctx test_ctx;
14571458
(void)ctx_c;
14581459
(void)ssl_c;
14591460
(void)ctx_s;
14601461
(void)ssl_s;
1461-
struct test_memio_ctx test_ctx;
14621462
(void)test_ctx;
14631463

14641464
/* --- Subtest 1: TLS 1.2 with AES-128-CBC-SHA256 (sha256_mac).
@@ -1807,11 +1807,11 @@ int test_tls_tlsx_validate_curves_coverage(void)
18071807
!defined(NO_AES) && defined(HAVE_AES_CBC)
18081808
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
18091809
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
1810+
struct test_memio_ctx test_ctx;
18101811
(void)ctx_c;
18111812
(void)ssl_c;
18121813
(void)ctx_s;
18131814
(void)ssl_s;
1814-
struct test_memio_ctx test_ctx;
18151815
(void)test_ctx;
18161816

18171817
/* --- Subtest 1: ECDHE-RSA cipher + client restricts to SECP256R1,
@@ -1954,11 +1954,11 @@ int test_tls_tlsx_psk_coverage(void)
19541954
!defined(NO_RSA) && defined(HAVE_ECC)
19551955
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
19561956
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
1957+
struct test_memio_ctx test_ctx;
19571958
(void)ctx_c;
19581959
(void)ssl_c;
19591960
(void)ctx_s;
19601961
(void)ssl_s;
1961-
struct test_memio_ctx test_ctx;
19621962
(void)test_ctx;
19631963

19641964
/* --- Subtest 1: full TLS 1.3 handshake followed by session-ticket
@@ -2185,11 +2185,11 @@ int test_tls_tlsx_keyshare_coverage(void)
21852185
!defined(NO_RSA) && defined(HAVE_ECC)
21862186
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
21872187
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
2188+
struct test_memio_ctx test_ctx;
21882189
(void)ctx_c;
21892190
(void)ssl_c;
21902191
(void)ctx_s;
21912192
(void)ssl_s;
2192-
struct test_memio_ctx test_ctx;
21932193
(void)test_ctx;
21942194

21952195
/* --- Subtest 1: TLS 1.3 normal handshake, client offers SECP256R1,
@@ -2326,11 +2326,11 @@ int test_tls_tlsx_csr_coverage(void)
23262326
!defined(NO_RSA) && defined(HAVE_ECC)
23272327
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
23282328
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
2329+
struct test_memio_ctx test_ctx;
23292330
(void)ctx_c;
23302331
(void)ssl_c;
23312332
(void)ctx_s;
23322333
(void)ssl_s;
2333-
struct test_memio_ctx test_ctx;
23342334
(void)test_ctx;
23352335

23362336
/* --- Subtest 1: TLS 1.2: client requests OCSP stapling via
@@ -2425,11 +2425,11 @@ int test_tls_tlsx_write_request_coverage(void)
24252425
!defined(NO_WOLFSSL_SERVER) && !defined(NO_RSA)
24262426
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
24272427
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
2428+
struct test_memio_ctx test_ctx;
24282429
(void)ctx_c;
24292430
(void)ssl_c;
24302431
(void)ctx_s;
24312432
(void)ssl_s;
2432-
struct test_memio_ctx test_ctx;
24332433
(void)test_ctx;
24342434

24352435
/* --- Subtest 1: TLS 1.2 client WriteRequest.
@@ -4272,11 +4272,11 @@ int test_tls_build_handshake_hash_batch4(void)
42724272

42734273
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
42744274
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
4275+
struct test_memio_ctx test_ctx;
42754276
(void)ctx_c;
42764277
(void)ssl_c;
42774278
(void)ctx_s;
42784279
(void)ssl_s;
4279-
struct test_memio_ctx test_ctx;
42804280
(void)test_ctx;
42814281

42824282
/* --- Subtest 1: TLS 1.2 with DHE-RSA-AES128-SHA (sha_mac <= sha256_mac).

0 commit comments

Comments
 (0)