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/ssl/ssl_cert.c b/ssl/ssl_cert.c index 277ee4d..3eaf499 100644 --- a/ssl/ssl_cert.c +++ b/ssl/ssl_cert.c
@@ -147,7 +147,7 @@ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); return NULL; } - memset(ret, 0, sizeof(CERT)); + OPENSSL_memset(ret, 0, sizeof(CERT)); return ret; } @@ -158,7 +158,7 @@ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); return NULL; } - memset(ret, 0, sizeof(CERT)); + OPENSSL_memset(ret, 0, sizeof(CERT)); if (cert->x509_leaf != NULL) { X509_up_ref(cert->x509_leaf); @@ -707,7 +707,8 @@ static const uint8_t kKeyUsageOID[3] = {0x55, 0x1d, 0x0f}; if (CBS_len(&oid) != sizeof(kKeyUsageOID) || - memcmp(CBS_data(&oid), kKeyUsageOID, sizeof(kKeyUsageOID)) != 0) { + OPENSSL_memcmp(CBS_data(&oid), kKeyUsageOID, sizeof(kKeyUsageOID)) != + 0) { continue; }