prevent undefined behavior when src and dst are equal
authorRoberto Guimaraes <rguimaraes@fastly.com>
Sun, 26 Feb 2017 23:47:40 +0000 (15:47 -0800)
committerRich Salz <rsalz@openssl.org>
Wed, 8 Mar 2017 14:48:49 +0000 (09:48 -0500)
CLA: trivial

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2750)

(cherry picked from commit 6aad9393680ccde591905c8d71da92a241756394)

ssl/ssl_sess.c

index 43cb1d371b98c7018d83a63b7a5f5fe5efd8f4d0..3f068840b974587f663f6170f572e01b5793c6fe 100644 (file)
@@ -814,7 +814,8 @@ int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid,
       return 0;
     }
     s->session_id_length = sid_len;
-    memcpy(s->session_id, sid, sid_len);
+    if (sid != s->session_id)
+        memcpy(s->session_id, sid, sid_len);
     return 1;
 }
 
@@ -895,7 +896,8 @@ int SSL_SESSION_set1_id_context(SSL_SESSION *s, const unsigned char *sid_ctx,
         return 0;
     }
     s->sid_ctx_length = sid_ctx_len;
-    memcpy(s->sid_ctx, sid_ctx, sid_ctx_len);
+    if (sid_ctx != s->sid_ctx)
+        memcpy(s->sid_ctx, sid_ctx, sid_ctx_len);
 
     return 1;
 }