Skip to content

Commit 7d38e9c

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 b067686 commit 7d38e9c

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
@@ -1705,7 +1705,7 @@ static int test_wolfSSL_use_AltPrivateKey_Id(void)
17051705
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Id(ssl, NULL, sizeof(id),
17061706
INVALID_DEVID), 0);
17071707

1708-
/* Positive test valid ID should succeed. */
1708+
/* Positive test - valid ID should succeed. */
17091709
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Id(ssl, id, sizeof(id),
17101710
INVALID_DEVID), 1);
17111711

@@ -1735,7 +1735,7 @@ static int test_wolfSSL_use_AltPrivateKey_Label(void)
17351735
0);
17361736
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(ssl, NULL, INVALID_DEVID), 0);
17371737

1738-
/* Positive test valid label should succeed. */
1738+
/* Positive test - valid label should succeed. */
17391739
ExpectIntEQ(wolfSSL_use_AltPrivateKey_Label(ssl, "test_label",
17401740
INVALID_DEVID), 1);
17411741

0 commit comments

Comments
 (0)