From: Matt Caswell Date: Wed, 1 May 2024 10:23:57 +0000 (+0100) Subject: Fix undefined behaviour in the event of a zero length session id X-Git-Tag: openssl-3.4.0-alpha1~592 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97c6489b39c966c6e5169b9b92ec5fa9a35c7ba3;p=thirdparty%2Fopenssl.git Fix undefined behaviour in the event of a zero length session id Don't attempt to memcpy a NULL pointer if the length is 0. Reviewed-by: Neil Horman Reviewed-by: Dmitry Belyavskiy Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/24309) --- diff --git a/ssl/ssl_sess.c b/ssl/ssl_sess.c index eaa9595f8c2..3857e027ee0 100644 --- a/ssl/ssl_sess.c +++ b/ssl/ssl_sess.c @@ -907,8 +907,9 @@ int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid, return 0; } s->session_id_length = sid_len; - if (sid != s->session_id) + if (sid != s->session_id && sid_len > 0) memcpy(s->session_id, sid, sid_len); + return 1; }