Skip to content

Commit eb7bac3

Browse files
Merge pull request wolfSSL#8399 from julek-wolfssl/cov-fixes-30-01-2025
Cov fixes
2 parents 9641dc7 + c36d230 commit eb7bac3

File tree

3 files changed

+43
-35
lines changed

3 files changed

+43
-35
lines changed

src/dtls.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ static int FindExtByType(WolfSSL_ConstVector* ret, word16 extType,
365365
ato16(exts.elements + idx, &type);
366366
idx += OPAQUE16_LEN;
367367
idx += ReadVector16(exts.elements + idx, &ext);
368-
if (idx > exts.size)
368+
if (idx > exts.size ||
369+
ext.elements + ext.size > exts.elements + exts.size)
369370
return BUFFER_ERROR;
370371
if (type == extType) {
371372
XMEMCPY(ret, &ext, sizeof(ext));
@@ -498,7 +499,7 @@ static int TlsCheckSupportedVersion(const WOLFSSL* ssl,
498499
ch->extension, &tlsxFound);
499500
if (ret != 0)
500501
return ret;
501-
if (!tlsxFound) {
502+
if (!tlsxFound || tlsxSupportedVersions.elements == NULL) {
502503
*isTls13 = 0;
503504
return 0;
504505
}
@@ -847,8 +848,6 @@ static int SendStatelessReplyDtls13(const WOLFSSL* ssl, WolfSSL_CH* ch)
847848
WOLFSSL* nonConstSSL = (WOLFSSL*)ssl;
848849
TLSX* sslExts = nonConstSSL->extensions;
849850

850-
if (ret != 0)
851-
goto dtls13_cleanup;
852851
nonConstSSL->options.tls = 1;
853852
nonConstSSL->options.tls1_1 = 1;
854853
nonConstSSL->options.tls1_3 = 1;
@@ -1221,7 +1220,7 @@ int TLSX_ConnectionID_Use(WOLFSSL* ssl)
12211220
info = (CIDInfo*)XMALLOC(sizeof(CIDInfo), ssl->heap, DYNAMIC_TYPE_TLSX);
12221221
if (info == NULL)
12231222
return MEMORY_ERROR;
1224-
ext = (WOLFSSL**)XMALLOC(sizeof(WOLFSSL**), ssl->heap, DYNAMIC_TYPE_TLSX);
1223+
ext = (WOLFSSL**)XMALLOC(sizeof(WOLFSSL*), ssl->heap, DYNAMIC_TYPE_TLSX);
12251224
if (ext == NULL) {
12261225
XFREE(info, ssl->heap, DYNAMIC_TYPE_TLSX);
12271226
return MEMORY_ERROR;

src/dtls13.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ int Dtls13RlAddPlaintextHeader(WOLFSSL* ssl, byte* out,
185185
/* seq[0] combines the epoch and 16 MSB of sequence number. We write on the
186186
epoch field and will overflow to the first two bytes of the sequence
187187
number */
188-
c32toa(seq[0], hdr->epoch);
188+
c16toa((word16)(seq[0] >> 16), hdr->epoch);
189+
c16toa((word16)seq[0], hdr->sequenceNumber);
189190
c32toa(seq[1], &hdr->sequenceNumber[2]);
190191

191192
c16toa(length, hdr->length);

tests/api.c

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

9095590956
static 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

Comments
 (0)