Skip to content

Commit 0ab5401

Browse files
committed
Fix cast-away-const in ws_ctx_ssl_set_tmp_dh: allocate DerBuffer with actual size and copy data instead of pointing at caller's const buffer, which caused FreeDer to free non-owned memory.
1 parent 4594f3f commit 0ab5401

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

src/ssl_load.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5930,12 +5930,10 @@ static int ws_ctx_ssl_set_tmp_dh(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
59305930

59315931
/* PemToDer allocates its own DER buffer. */
59325932
if ((res == 1) && (format != WOLFSSL_FILETYPE_PEM)) {
5933-
/* Create an empty DER buffer. */
5934-
ret = AllocDer(&der, 0, DH_PARAM_TYPE, heap);
5933+
/* Create a DER buffer and copy in the encoded DH parameters. */
5934+
ret = AllocDer(&der, (word32)sz, DH_PARAM_TYPE, heap);
59355935
if (ret == 0) {
5936-
/* Assign encoded DH parameters to DER buffer. */
5937-
der->buffer = (byte*)buf;
5938-
der->length = (word32)sz;
5936+
XMEMCPY(der->buffer, buf, (word32)sz);
59395937
}
59405938
else {
59415939
res = ret;

tests/api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ static int test_wolfSSL_use_AltPrivateKey_Id(void)
17181718
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Id(ssl, NULL, sizeof(id),
17191719
INVALID_DEVID), 0);
17201720

1721-
/* Positive test valid ID should succeed. */
1721+
/* Positive test - valid ID should succeed. */
17221722
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Id(ssl, id, sizeof(id),
17231723
INVALID_DEVID), 1);
17241724

@@ -1748,7 +1748,7 @@ static int test_wolfSSL_use_AltPrivateKey_Label(void)
17481748
0);
17491749
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(ssl, NULL, INVALID_DEVID), 0);
17501750

1751-
/* Positive test valid label should succeed. */
1751+
/* Positive test - valid label should succeed. */
17521752
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(ssl, "test_label",
17531753
INVALID_DEVID), 1);
17541754

0 commit comments

Comments
 (0)