From 1d5f4a6664e268b5ceee9b5fd701a869d5a9ce69 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Mon, 18 Oct 2021 14:38:47 +0200 Subject: [PATCH] #118 --- src/keys.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/keys.c b/src/keys.c index 654ac071a..9b80d6821 100644 --- a/src/keys.c +++ b/src/keys.c @@ -3119,6 +3119,12 @@ int SetKeysSide(WOLFSSL* ssl, enum encrypt_side side) if (copy) { int clientCopy = 0; + /* Sanity check that keys == ssl->secure_renegotiation->tmp_keys. + * Otherwise the memcpy calls would copy overlapping memory + * and cause UB. Fail early. */ + if (keys == &ssl->keys) + return BAD_FUNC_ARG; + if (ssl->options.side == WOLFSSL_CLIENT_END && wc_encrypt) clientCopy = 1; else if (ssl->options.side == WOLFSSL_SERVER_END && wc_decrypt)