Fix build with GCC 4.9.2 and -Wtype-limits.
gRPC builds on Debian Jessie, which has GCC 4.9.2, and builds with -Wtype-limits, which makes it warn about code intended for 64-bit systems when building on 32-bit systems. We have tried to avoid these issues with Clang previously by guarding with “sizeof(size_t) > 4”, but this version of GCC isn't smart enough to figure that out. Change-Id: I800ceb3891436fa7c81474ede4b8656021568357 Reviewed-on: https://boringssl-review.googlesource.com/28247 Reviewed-by: David Benjamin <davidben@google.com> Commit-Queue: David Benjamin <davidben@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
parent
bb3a456930
commit
f64c373784
@ -158,9 +158,7 @@ static int ccm128_init_state(const CCM128_CONTEXT *ctx,
|
||||
size_t remaining_blocks = 2 * ((plaintext_len + 15) / 16) + 1;
|
||||
if (plaintext_len + 15 < plaintext_len ||
|
||||
remaining_blocks + blocks < blocks ||
|
||||
// Silence Clang's unhelpful -Wtautological-constant-out-of-range-compare
|
||||
// warning.
|
||||
(sizeof(size_t) > 4 && remaining_blocks + blocks > UINT64_C(1) << 61)) {
|
||||
(uint64_t) remaining_blocks + blocks > UINT64_C(1) << 61) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -536,6 +536,20 @@ bool dtls1_finish_message(SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// ssl_size_t_greater_than_32_bits returns whether |v| exceeds the bounds of a
|
||||
// 32-bit value. The obvious thing doesn't work because, in some 32-bit build
|
||||
// configurations, the compiler warns that the test is always false and breaks
|
||||
// the build.
|
||||
static bool ssl_size_t_greater_than_32_bits(size_t v) {
|
||||
#if defined(OPENSSL_64_BIT)
|
||||
return v > 0xffffffff;
|
||||
#elif defined(OPENSSL_32_BIT)
|
||||
return false;
|
||||
#else
|
||||
#error "Building for neither 32- nor 64-bits."
|
||||
#endif
|
||||
}
|
||||
|
||||
// add_outgoing adds a new handshake message or ChangeCipherSpec to the current
|
||||
// outgoing flight. It returns true on success and false on error.
|
||||
static bool add_outgoing(SSL *ssl, bool is_ccs, Array<uint8_t> data) {
|
||||
@ -550,7 +564,7 @@ static bool add_outgoing(SSL *ssl, bool is_ccs, Array<uint8_t> data) {
|
||||
(1 << 8 * sizeof(ssl->d1->outgoing_messages_len)),
|
||||
"outgoing_messages_len is too small");
|
||||
if (ssl->d1->outgoing_messages_len >= SSL_MAX_HANDSHAKE_FLIGHT ||
|
||||
static_cast<uint64_t>(data.size()) > 0xffffffff) {
|
||||
ssl_size_t_greater_than_32_bits(data.size())) {
|
||||
assert(false);
|
||||
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
||||
return false;
|
||||
|
@ -238,8 +238,8 @@ int ssl3_flush_flight(SSL *ssl) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (static_cast<uint64_t>(ssl->s3->pending_flight->length) > 0xffffffff ||
|
||||
ssl->s3->pending_flight->length > INT_MAX) {
|
||||
static_assert(INT_MAX <= 0xffffffff, "int is larger than 32 bits");
|
||||
if (ssl->s3->pending_flight->length > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user