Prevent undefined behavior in memcpy call.
authorRoberto Guimaraes <rguimaraes@fastly.com>
Wed, 8 Mar 2017 14:54:04 +0000 (09:54 -0500)
committerRich Salz <rsalz@openssl.org>
Wed, 8 Mar 2017 14:55:39 +0000 (09:55 -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 c3369a44aea7e215ba6c3f230d12f9febb296c6f..f50f5142126f80e19a599ed8b8380f203a9aa24a 100644 (file)
@@ -1006,7 +1006,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 (s->sid_ctx != sid_ctx)
+        memcpy(s->sid_ctx, sid_ctx, sid_ctx_len);
 
     return 1;
 }