Fix undefined behaviour in the event of a zero length session id
authorMatt Caswell <matt@openssl.org>
Wed, 1 May 2024 10:23:57 +0000 (11:23 +0100)
committerTomas Mraz <tomas@openssl.org>
Mon, 6 May 2024 08:44:22 +0000 (10:44 +0200)
Don't attempt to memcpy a NULL pointer if the length is 0.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24309)

ssl/ssl_sess.c

index eaa9595f8c2f2ecbcb064848d6f075fcea270362..3857e027ee0d1b1cf0a303e80a9ebca245710df3 100644 (file)
@@ -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;
 }