Skip to content

Commit f5658f9

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 f5658f9

1 file changed

Lines changed: 3 additions & 5 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;

0 commit comments

Comments
 (0)