@@ -53356,54 +53356,54 @@ static int test_wolfSSL_a2i_ASN1_INTEGER(void)
5335653356 ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, NULL, -1), 0);
5335753357 ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, NULL, -1), 0);
5335853358 ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, tmp, -1), 0);
53359- ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, 1024 ), 0);
53360- ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, tmp, 1024 ), 0);
53361- ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, tmp, 1024 ), 0);
53362- ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, NULL, 1024 ), 0);
53359+ ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, sizeof(tmp) ), 0);
53360+ ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, tmp, sizeof(tmp) ), 0);
53361+ ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, tmp, sizeof(tmp) ), 0);
53362+ ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, NULL, sizeof(tmp) ), 0);
5336353363 ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, -1), 0);
5336453364 ExpectIntEQ(i2a_ASN1_INTEGER(NULL, NULL), 0);
5336553365 ExpectIntEQ(i2a_ASN1_INTEGER(bio, NULL), 0);
5336653366 ExpectIntEQ(i2a_ASN1_INTEGER(NULL, ai), 0);
5336753367
5336853368 /* No data to read from BIO. */
53369- ExpectIntEQ(a2i_ASN1_INTEGER(out, ai, tmp, 1024 ), 0);
53369+ ExpectIntEQ(a2i_ASN1_INTEGER(out, ai, tmp, sizeof(tmp) ), 0);
5337053370
5337153371 /* read first line */
53372- ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024 ), 1);
53372+ ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, sizeof(tmp) ), 1);
5337353373 ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 6);
53374- XMEMSET(tmp, 0, 1024 );
53375- tmpSz = BIO_read(out, tmp, 1024 );
53374+ XMEMSET(tmp, 0, sizeof(tmp) );
53375+ tmpSz = BIO_read(out, tmp, sizeof(tmp) );
5337653376 ExpectIntEQ(tmpSz, 6);
5337753377 ExpectIntEQ(XMEMCMP(tmp, expected1, tmpSz), 0);
5337853378
5337953379 /* fail on second line (not % 2) */
53380- ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024 ), 0);
53380+ ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, sizeof(tmp) ), 0);
5338153381
5338253382 /* read 3rd long line */
53383- ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024 ), 1);
53383+ ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, sizeof(tmp) ), 1);
5338453384 ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 30);
53385- XMEMSET(tmp, 0, 1024 );
53386- tmpSz = BIO_read(out, tmp, 1024 );
53385+ XMEMSET(tmp, 0, sizeof(tmp) );
53386+ tmpSz = BIO_read(out, tmp, sizeof(tmp) );
5338753387 ExpectIntEQ(tmpSz, 30);
5338853388 ExpectIntEQ(XMEMCMP(tmp, expected2, tmpSz), 0);
5338953389
5339053390 /* fail on empty line */
53391- ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024 ), 0);
53391+ ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, sizeof(tmp) ), 0);
5339253392
5339353393 BIO_free(bio);
5339453394 bio = NULL;
5339553395
5339653396 /* Make long integer, requiring dynamic memory, even longer. */
5339753397 ExpectNotNull(bio = BIO_new_mem_buf(longStr, -1));
53398- ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024 ), 1);
53398+ ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, sizeof(tmp) ), 1);
5339953399 ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 48);
53400- XMEMSET(tmp, 0, 1024 );
53401- tmpSz = BIO_read(out, tmp, 1024 );
53400+ XMEMSET(tmp, 0, sizeof(tmp) );
53401+ tmpSz = BIO_read(out, tmp, sizeof(tmp) );
5340253402 ExpectIntEQ(tmpSz, 48);
53403- ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024 ), 1);
53403+ ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, sizeof(tmp) ), 1);
5340453404 ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 56);
53405- XMEMSET(tmp, 0, 1024 );
53406- tmpSz = BIO_read(out, tmp, 1024 );
53405+ XMEMSET(tmp, 0, sizeof(tmp) );
53406+ tmpSz = BIO_read(out, tmp, sizeof(tmp) );
5340753407 ExpectIntEQ(tmpSz, 56);
5340853408 ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(ai, 1), 1);
5340953409 BIO_free(bio);
@@ -90726,9 +90726,10 @@ static void test_wolfSSL_dtls13_fragments_spammer(WOLFSSL* ssl)
9072690726 XMEMSET(&delay, 0, sizeof(delay));
9072790727 delay.tv_nsec = 10000000; /* wait 0.01 seconds */
9072890728 c16toa(msg_number, b + msg_offset);
90729- sendSz = BuildTls13Message(ssl, sendBuf, sendSz, b,
90729+ ret = sendSz = BuildTls13Message(ssl, sendBuf, sendSz, b,
9073090730 (int)idx, handshake, 0, 0, 0);
90731- ret = (int)send(fd, sendBuf, (size_t)sendSz, 0);
90731+ if (sendSz > 0)
90732+ ret = (int)send(fd, sendBuf, (size_t)sendSz, 0);
9073290733 nanosleep(&delay, NULL);
9073390734 }
9073490735}
@@ -90954,8 +90955,9 @@ static byte test_AEAD_done = 0;
9095490955
9095590956static int test_AEAD_cbiorecv(WOLFSSL *ssl, char *buf, int sz, void *ctx)
9095690957{
90957- int ret = (int)recv(wolfSSL_get_fd(ssl), buf, sz, 0);
90958- if (ret > 0) {
90958+ int fd = wolfSSL_get_fd(ssl);
90959+ int ret = -1;
90960+ if (fd >= 0 && (ret = (int)recv(fd, buf, sz, 0)) > 0) {
9095990961 if (test_AEAD_fail_decryption) {
9096090962 /* Modify the packet to trigger a decryption failure */
9096190963 buf[ret/2] ^= 0xFF;
@@ -91271,12 +91273,16 @@ static void test_wolfSSL_dtls_send_ch_with_invalid_cookie(WOLFSSL* ssl)
9127191273 };
9127291274
9127391275 fd = wolfSSL_get_wfd(ssl);
91274- ret = (int)send(fd, ch_msh_invalid_cookie, sizeof(ch_msh_invalid_cookie), 0);
91275- AssertIntGT(ret, 0);
91276- /* should reply with an illegal_parameter reply */
91277- ret = (int)recv(fd, alert_reply, sizeof(alert_reply), 0);
91278- AssertIntEQ(ret, sizeof(expected_alert_reply));
91279- AssertIntEQ(XMEMCMP(alert_reply, expected_alert_reply, sizeof(expected_alert_reply)), 0);
91276+ if (fd >= 0) {
91277+ ret = (int)send(fd, ch_msh_invalid_cookie,
91278+ sizeof(ch_msh_invalid_cookie), 0);
91279+ AssertIntGT(ret, 0);
91280+ /* should reply with an illegal_parameter reply */
91281+ ret = (int)recv(fd, alert_reply, sizeof(alert_reply), 0);
91282+ AssertIntEQ(ret, sizeof(expected_alert_reply));
91283+ AssertIntEQ(XMEMCMP(alert_reply, expected_alert_reply,
91284+ sizeof(expected_alert_reply)), 0);
91285+ }
9128091286}
9128191287#endif
9128291288
@@ -99169,6 +99175,8 @@ static int test_dtls_frag_ch_count_records(byte* b, int len)
9916999175 records++;
9917099176 dtlsRH = (DtlsRecordLayerHeader*)b;
9917199177 recordLen = (dtlsRH->length[0] << 8) | dtlsRH->length[1];
99178+ if (recordLen > (size_t)len)
99179+ break;
9917299180 b += sizeof(DtlsRecordLayerHeader) + recordLen;
9917399181 len -= sizeof(DtlsRecordLayerHeader) + recordLen;
9917499182 }
0 commit comments