Work around language and compiler bug in memcpy, etc. Most C standard library functions are undefined if passed NULL, even when the corresponding length is zero. This gives them (and, in turn, all functions which call them) surprising behavior on empty arrays. Some compilers will miscompile code due to this rule. See also https://www.imperialviolet.org/2016/06/26/nonnull.html Add OPENSSL_memcpy, etc., wrappers which avoid this problem. BUG=23 Change-Id: I95f42b23e92945af0e681264fffaf578e7f8465e Reviewed-on: https://boringssl-review.googlesource.com/12928 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
diff --git a/tool/transport_common.cc b/tool/transport_common.cc index 0fee377..9b8715d 100644 --- a/tool/transport_common.cc +++ b/tool/transport_common.cc
@@ -47,6 +47,7 @@ #include <openssl/ssl.h> #include <openssl/x509.h> +#include "../crypto/internal.h" #include "internal.h" #include "transport_common.h" @@ -98,7 +99,7 @@ } struct addrinfo hint, *result; - memset(&hint, 0, sizeof(hint)); + OPENSSL_memset(&hint, 0, sizeof(hint)); hint.ai_family = AF_UNSPEC; hint.ai_socktype = SOCK_STREAM; @@ -151,7 +152,7 @@ bool Accept(int *out_sock, const std::string &port) { struct sockaddr_in6 addr, cli_addr; socklen_t cli_addr_len = sizeof(cli_addr); - memset(&addr, 0, sizeof(addr)); + OPENSSL_memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; addr.sin6_addr = IN6ADDR_ANY_INIT; @@ -434,7 +435,7 @@ out_line->assign(buf_, length); buf_len_ -= i + 1; - memmove(buf_, &buf_[i + 1], buf_len_); + OPENSSL_memmove(buf_, &buf_[i + 1], buf_len_); return true; }