[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT (#36496)

[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT
Replacing GPR_ASSERT with absl CHECK.
These changes have been made using string replacement and regex.
Will not be replacing all instances of CHECK with CHECK_EQ , CHECK_NE etc because there are too many callsites. Only ones which are doable using very simple regex with least chance of failure will be replaced.
Given that we have 5000+ instances of GPR_ASSERT to edit, Doing it manually is too much work for both the author and reviewer.

Closes #36496

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36496 from tanvi-jagtap:tjagtap_src_core_tsi 4a5a4638fa
PiperOrigin-RevId: 630588538
pull/36526/head
Tanvi Jagtap 9 months ago committed by Copybara-Service
parent 9233eb49b2
commit adf042bb41
  1. 6
      BUILD
  2. 72
      src/core/tsi/alts/handshaker/alts_handshaker_client.cc
  3. 6
      src/core/tsi/alts/handshaker/alts_shared_resource.cc
  4. 38
      src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc
  5. 6
      src/core/tsi/alts/handshaker/alts_tsi_utils.cc
  6. 6
      src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc
  7. 11
      src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc
  8. 6
      src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc
  9. 7
      src/core/tsi/fake_transport_security.cc
  10. 8
      src/core/tsi/ssl/key_logging/ssl_key_logging.cc
  11. 18
      src/core/tsi/ssl/session_cache/ssl_session_cache.cc
  12. 6
      src/core/tsi/ssl/session_cache/ssl_session_openssl.cc
  13. 35
      src/core/tsi/ssl_transport_security.cc
  14. 17
      src/core/tsi/ssl_transport_security_utils.cc

@ -3957,6 +3957,9 @@ grpc_cc_library(
hdrs = [
"//src/core:tsi/fake_transport_security.h",
],
external_deps = [
"absl/log:check",
],
language = "c++",
visibility = [
"@grpc:public",
@ -4074,6 +4077,7 @@ grpc_cc_library(
"//src/core:tsi/alts/handshaker/alts_tsi_utils.h",
],
external_deps = [
"absl/log:check",
"absl/strings",
"@com_google_protobuf//upb:base",
"@com_google_protobuf//upb:mem",
@ -4133,6 +4137,7 @@ grpc_cc_library(
"//src/core:tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h",
],
external_deps = [
"absl/log:check",
"absl/types:span",
"libcrypto",
"libssl",
@ -4163,6 +4168,7 @@ grpc_cc_library(
"//src/core:tsi/ssl/session_cache/ssl_session_cache.h",
],
external_deps = [
"absl/log:check",
"absl/memory",
"libssl",
],

@ -20,6 +20,7 @@
#include <list>
#include "absl/log/check.h"
#include "absl/strings/numbers.h"
#include "upb/mem/arena.hpp"
@ -117,13 +118,13 @@ typedef struct alts_grpc_handshaker_client {
static void handshaker_client_send_buffer_destroy(
alts_grpc_handshaker_client* client) {
GPR_ASSERT(client != nullptr);
CHECK_NE(client, nullptr);
grpc_byte_buffer_destroy(client->send_buffer);
client->send_buffer = nullptr;
}
static bool is_handshake_finished_properly(grpc_gcp_HandshakerResp* resp) {
GPR_ASSERT(resp != nullptr);
CHECK_NE(resp, nullptr);
return grpc_gcp_HandshakerResp_result(resp) != nullptr;
}
@ -156,7 +157,7 @@ static void maybe_complete_tsi_next(
grpc_core::MutexLock lock(&client->mu);
client->receive_status_finished |= receive_status_finished;
if (pending_recv_message_result != nullptr) {
GPR_ASSERT(client->pending_recv_message_result == nullptr);
CHECK_EQ(client->pending_recv_message_result, nullptr);
client->pending_recv_message_result = pending_recv_message_result;
}
if (client->pending_recv_message_result == nullptr) {
@ -197,7 +198,7 @@ static void handle_response_done(alts_grpc_handshaker_client* client,
void alts_handshaker_client_handle_response(alts_handshaker_client* c,
bool is_ok) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
grpc_byte_buffer* recv_buffer = client->recv_buffer;
@ -312,7 +313,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
static tsi_result continue_make_grpc_call(alts_grpc_handshaker_client* client,
bool is_start) {
GPR_ASSERT(client != nullptr);
CHECK_NE(client, nullptr);
grpc_op ops[kHandshakerClientOpNum];
memset(ops, 0, sizeof(ops));
grpc_op* op = ops;
@ -325,34 +326,34 @@ static tsi_result continue_make_grpc_call(alts_grpc_handshaker_client* client,
op->flags = 0;
op->reserved = nullptr;
op++;
GPR_ASSERT(op - ops <= kHandshakerClientOpNum);
CHECK(op - ops <= kHandshakerClientOpNum);
gpr_ref(&client->refs);
grpc_call_error call_error =
client->grpc_caller(client->call, ops, static_cast<size_t>(op - ops),
&client->on_status_received);
// TODO(apolcyn): return the error here instead, as done for other ops?
GPR_ASSERT(call_error == GRPC_CALL_OK);
CHECK_EQ(call_error, GRPC_CALL_OK);
memset(ops, 0, sizeof(ops));
op = ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 0;
op++;
GPR_ASSERT(op - ops <= kHandshakerClientOpNum);
CHECK(op - ops <= kHandshakerClientOpNum);
op->op = GRPC_OP_RECV_INITIAL_METADATA;
op->data.recv_initial_metadata.recv_initial_metadata =
&client->recv_initial_metadata;
op++;
GPR_ASSERT(op - ops <= kHandshakerClientOpNum);
CHECK(op - ops <= kHandshakerClientOpNum);
}
op->op = GRPC_OP_SEND_MESSAGE;
op->data.send_message.send_message = client->send_buffer;
op++;
GPR_ASSERT(op - ops <= kHandshakerClientOpNum);
CHECK(op - ops <= kHandshakerClientOpNum);
op->op = GRPC_OP_RECV_MESSAGE;
op->data.recv_message.recv_message = &client->recv_buffer;
op++;
GPR_ASSERT(op - ops <= kHandshakerClientOpNum);
GPR_ASSERT(client->grpc_caller != nullptr);
CHECK(op - ops <= kHandshakerClientOpNum);
CHECK_NE(client->grpc_caller, nullptr);
if (client->grpc_caller(client->call, ops, static_cast<size_t>(op - ops),
&client->on_handshaker_service_resp_recv) !=
GRPC_CALL_OK) {
@ -450,7 +451,7 @@ void HandshakeDone(bool is_client) {
/// make a grpc call.
///
static tsi_result make_grpc_call(alts_handshaker_client* c, bool is_start) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
if (is_start) {
@ -500,7 +501,7 @@ static grpc_byte_buffer* get_serialized_handshaker_req(
// Create and populate a client_start handshaker request, then serialize it.
static grpc_byte_buffer* get_serialized_start_client(
alts_handshaker_client* c) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
upb::Arena arena;
@ -565,8 +566,8 @@ static tsi_result handshaker_client_start_client(alts_handshaker_client* c) {
// Create and populate a start_server handshaker request, then serialize it.
static grpc_byte_buffer* get_serialized_start_server(
alts_handshaker_client* c, grpc_slice* bytes_received) {
GPR_ASSERT(c != nullptr);
GPR_ASSERT(bytes_received != nullptr);
CHECK_NE(c, nullptr);
CHECK_NE(bytes_received, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
@ -623,7 +624,7 @@ static tsi_result handshaker_client_start_server(alts_handshaker_client* c,
// Create and populate a next handshaker request, then serialize it.
static grpc_byte_buffer* get_serialized_next(grpc_slice* bytes_received) {
GPR_ASSERT(bytes_received != nullptr);
CHECK_NE(bytes_received, nullptr);
upb::Arena arena;
grpc_gcp_HandshakerReq* req = grpc_gcp_HandshakerReq_new(arena.ptr());
grpc_gcp_NextHandshakeMessageReq* next =
@ -661,7 +662,7 @@ static tsi_result handshaker_client_next(alts_handshaker_client* c,
}
static void handshaker_client_shutdown(alts_handshaker_client* c) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
if (client->call != nullptr) {
@ -759,7 +760,8 @@ namespace internal {
void alts_handshaker_client_set_grpc_caller_for_testing(
alts_handshaker_client* c, alts_grpc_caller caller) {
GPR_ASSERT(c != nullptr && caller != nullptr);
CHECK(c != nullptr);
CHECK_NE(caller, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
client->grpc_caller = caller;
@ -767,7 +769,7 @@ void alts_handshaker_client_set_grpc_caller_for_testing(
grpc_byte_buffer* alts_handshaker_client_get_send_buffer_for_testing(
alts_handshaker_client* c) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
return client->send_buffer;
@ -775,7 +777,7 @@ grpc_byte_buffer* alts_handshaker_client_get_send_buffer_for_testing(
grpc_byte_buffer** alts_handshaker_client_get_recv_buffer_addr_for_testing(
alts_handshaker_client* c) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
return &client->recv_buffer;
@ -783,7 +785,7 @@ grpc_byte_buffer** alts_handshaker_client_get_recv_buffer_addr_for_testing(
grpc_metadata_array* alts_handshaker_client_get_initial_metadata_for_testing(
alts_handshaker_client* c) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
return &client->recv_initial_metadata;
@ -791,7 +793,7 @@ grpc_metadata_array* alts_handshaker_client_get_initial_metadata_for_testing(
void alts_handshaker_client_set_recv_bytes_for_testing(
alts_handshaker_client* c, grpc_slice* recv_bytes) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
client->recv_bytes = CSliceRef(*recv_bytes);
@ -801,7 +803,7 @@ void alts_handshaker_client_set_fields_for_testing(
alts_handshaker_client* c, alts_tsi_handshaker* handshaker,
tsi_handshaker_on_next_done_cb cb, void* user_data,
grpc_byte_buffer* recv_buffer, bool inject_read_failure) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
client->handshaker = handshaker;
@ -814,22 +816,22 @@ void alts_handshaker_client_set_fields_for_testing(
void alts_handshaker_client_check_fields_for_testing(
alts_handshaker_client* c, tsi_handshaker_on_next_done_cb cb,
void* user_data, bool has_sent_start_message, grpc_slice* recv_bytes) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
GPR_ASSERT(client->cb == cb);
GPR_ASSERT(client->user_data == user_data);
CHECK(client->cb == cb);
CHECK(client->user_data == user_data);
if (recv_bytes != nullptr) {
GPR_ASSERT(grpc_slice_cmp(client->recv_bytes, *recv_bytes) == 0);
CHECK_EQ(grpc_slice_cmp(client->recv_bytes, *recv_bytes), 0);
}
GPR_ASSERT(alts_tsi_handshaker_get_has_sent_start_message_for_testing(
client->handshaker) == has_sent_start_message);
CHECK(alts_tsi_handshaker_get_has_sent_start_message_for_testing(
client->handshaker) == has_sent_start_message);
}
void alts_handshaker_client_set_vtable_for_testing(
alts_handshaker_client* c, alts_handshaker_client_vtable* vtable) {
GPR_ASSERT(c != nullptr);
GPR_ASSERT(vtable != nullptr);
CHECK_NE(c, nullptr);
CHECK_NE(vtable, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
client->base.vtable = vtable;
@ -837,7 +839,7 @@ void alts_handshaker_client_set_vtable_for_testing(
alts_tsi_handshaker* alts_handshaker_client_get_handshaker_for_testing(
alts_handshaker_client* c) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
return client->handshaker;
@ -845,7 +847,7 @@ alts_tsi_handshaker* alts_handshaker_client_get_handshaker_for_testing(
void alts_handshaker_client_set_cb_for_testing(
alts_handshaker_client* c, tsi_handshaker_on_next_done_cb cb) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
client->cb = cb;
@ -853,7 +855,7 @@ void alts_handshaker_client_set_cb_for_testing(
grpc_closure* alts_handshaker_client_get_closure_for_testing(
alts_handshaker_client* c) {
GPR_ASSERT(c != nullptr);
CHECK_NE(c, nullptr);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
return &client->on_handshaker_service_resp_recv;

@ -18,6 +18,8 @@
#include "src/core/tsi/alts/handshaker/alts_shared_resource.h"
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
@ -36,11 +38,11 @@ static void thread_worker(void* /*arg*/) {
grpc_event event =
grpc_completion_queue_next(g_alts_resource_dedicated.cq,
gpr_inf_future(GPR_CLOCK_REALTIME), nullptr);
GPR_ASSERT(event.type != GRPC_QUEUE_TIMEOUT);
CHECK(event.type != GRPC_QUEUE_TIMEOUT);
if (event.type == GRPC_QUEUE_SHUTDOWN) {
break;
}
GPR_ASSERT(event.type == GRPC_OP_COMPLETE);
CHECK(event.type == GRPC_OP_COMPLETE);
alts_handshaker_client* client =
static_cast<alts_handshaker_client*>(event.tag);
alts_handshaker_client_handle_response(client, event.success);

@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include "absl/log/check.h"
#include "upb/mem/arena.hpp"
#include <grpc/credentials.h>
@ -92,14 +93,14 @@ static tsi_result handshaker_result_extract_peer(
alts_tsi_handshaker_result* result =
reinterpret_cast<alts_tsi_handshaker_result*>(
const_cast<tsi_handshaker_result*>(self));
GPR_ASSERT(kTsiAltsNumOfPeerProperties == 5);
CHECK_EQ(kTsiAltsNumOfPeerProperties, 5u);
tsi_result ok = tsi_construct_peer(kTsiAltsNumOfPeerProperties, peer);
int index = 0;
if (ok != TSI_OK) {
gpr_log(GPR_ERROR, "Failed to construct tsi peer");
return ok;
}
GPR_ASSERT(&peer->properties[index] != nullptr);
CHECK_NE(&peer->properties[index], nullptr);
ok = tsi_construct_string_peer_property_from_cstring(
TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_ALTS_CERTIFICATE_TYPE,
&peer->properties[index]);
@ -109,7 +110,7 @@ static tsi_result handshaker_result_extract_peer(
return ok;
}
index++;
GPR_ASSERT(&peer->properties[index] != nullptr);
CHECK_NE(&peer->properties[index], nullptr);
ok = tsi_construct_string_peer_property_from_cstring(
TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY, result->peer_identity,
&peer->properties[index]);
@ -118,7 +119,7 @@ static tsi_result handshaker_result_extract_peer(
gpr_log(GPR_ERROR, "Failed to set tsi peer property");
}
index++;
GPR_ASSERT(&peer->properties[index] != nullptr);
CHECK_NE(&peer->properties[index], nullptr);
ok = tsi_construct_string_peer_property(
TSI_ALTS_RPC_VERSIONS,
reinterpret_cast<char*>(GRPC_SLICE_START_PTR(result->rpc_versions)),
@ -128,7 +129,7 @@ static tsi_result handshaker_result_extract_peer(
gpr_log(GPR_ERROR, "Failed to set tsi peer property");
}
index++;
GPR_ASSERT(&peer->properties[index] != nullptr);
CHECK_NE(&peer->properties[index], nullptr);
ok = tsi_construct_string_peer_property(
TSI_ALTS_CONTEXT,
reinterpret_cast<char*>(GRPC_SLICE_START_PTR(result->serialized_context)),
@ -138,7 +139,7 @@ static tsi_result handshaker_result_extract_peer(
gpr_log(GPR_ERROR, "Failed to set tsi peer property");
}
index++;
GPR_ASSERT(&peer->properties[index] != nullptr);
CHECK_NE(&peer->properties[index], nullptr);
ok = tsi_construct_string_peer_property_from_cstring(
TSI_SECURITY_LEVEL_PEER_PROPERTY,
tsi_security_level_to_string(TSI_PRIVACY_AND_INTEGRITY),
@ -147,7 +148,7 @@ static tsi_result handshaker_result_extract_peer(
tsi_peer_destruct(peer);
gpr_log(GPR_ERROR, "Failed to set tsi peer property");
}
GPR_ASSERT(++index == kTsiAltsNumOfPeerProperties);
CHECK(++index == kTsiAltsNumOfPeerProperties);
return ok;
}
@ -423,7 +424,7 @@ static tsi_result alts_tsi_handshaker_continue_handshaker_next(
handshaker->handshaker_service_url);
handshaker->interested_parties =
grpc_alts_get_shared_resource_dedicated()->interested_parties;
GPR_ASSERT(handshaker->interested_parties != nullptr);
CHECK_NE(handshaker->interested_parties, nullptr);
}
grpc_iomgr_cb_func grpc_cb = handshaker->channel == nullptr
? on_handshaker_service_resp_recv_dedicated
@ -445,7 +446,7 @@ static tsi_result alts_tsi_handshaker_continue_handshaker_next(
}
{
grpc_core::MutexLock lock(&handshaker->mu);
GPR_ASSERT(handshaker->client == nullptr);
CHECK_EQ(handshaker->client, nullptr);
handshaker->client = client;
if (handshaker->shutdown) {
gpr_log(GPR_INFO, "TSI handshake shutdown");
@ -457,8 +458,8 @@ static tsi_result alts_tsi_handshaker_continue_handshaker_next(
}
if (handshaker->channel == nullptr &&
handshaker->client_vtable_for_testing == nullptr) {
GPR_ASSERT(grpc_cq_begin_op(grpc_alts_get_shared_resource_dedicated()->cq,
handshaker->client));
CHECK(grpc_cq_begin_op(grpc_alts_get_shared_resource_dedicated()->cq,
handshaker->client));
}
grpc_slice slice = (received_bytes == nullptr || received_bytes_size == 0)
? grpc_empty_slice()
@ -500,7 +501,7 @@ static void alts_tsi_handshaker_create_channel(
alts_tsi_handshaker_continue_handshaker_next_args* next_args =
static_cast<alts_tsi_handshaker_continue_handshaker_next_args*>(arg);
alts_tsi_handshaker* handshaker = next_args->handshaker;
GPR_ASSERT(handshaker->channel == nullptr);
CHECK_EQ(handshaker->channel, nullptr);
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
// Disable retries so that we quickly get a signal when the
// handshake server is not reachable.
@ -592,7 +593,7 @@ static tsi_result handshaker_next_dedicated(
}
static void handshaker_shutdown(tsi_handshaker* self) {
GPR_ASSERT(self != nullptr);
CHECK_NE(self, nullptr);
alts_tsi_handshaker* handshaker =
reinterpret_cast<alts_tsi_handshaker*>(self);
grpc_core::MutexLock lock(&handshaker->mu);
@ -638,7 +639,7 @@ static const tsi_handshaker_vtable handshaker_vtable_dedicated = {
handshaker_shutdown};
bool alts_tsi_handshaker_has_shutdown(alts_tsi_handshaker* handshaker) {
GPR_ASSERT(handshaker != nullptr);
CHECK_NE(handshaker, nullptr);
grpc_core::MutexLock lock(&handshaker->mu);
return handshaker->shutdown;
}
@ -676,7 +677,8 @@ tsi_result alts_tsi_handshaker_create(
void alts_tsi_handshaker_result_set_unused_bytes(tsi_handshaker_result* result,
grpc_slice* recv_bytes,
size_t bytes_consumed) {
GPR_ASSERT(recv_bytes != nullptr && result != nullptr);
CHECK(recv_bytes != nullptr);
CHECK_NE(result, nullptr);
if (GRPC_SLICE_LENGTH(*recv_bytes) == bytes_consumed) {
return;
}
@ -695,19 +697,19 @@ namespace internal {
bool alts_tsi_handshaker_get_has_sent_start_message_for_testing(
alts_tsi_handshaker* handshaker) {
GPR_ASSERT(handshaker != nullptr);
CHECK_NE(handshaker, nullptr);
return handshaker->has_sent_start_message;
}
void alts_tsi_handshaker_set_client_vtable_for_testing(
alts_tsi_handshaker* handshaker, alts_handshaker_client_vtable* vtable) {
GPR_ASSERT(handshaker != nullptr);
CHECK_NE(handshaker, nullptr);
handshaker->client_vtable_for_testing = vtable;
}
bool alts_tsi_handshaker_get_is_client_for_testing(
alts_tsi_handshaker* handshaker) {
GPR_ASSERT(handshaker != nullptr);
CHECK_NE(handshaker, nullptr);
return handshaker->is_client;
}

@ -18,6 +18,8 @@
#include "src/core/tsi/alts/handshaker/alts_tsi_utils.h"
#include "absl/log/check.h"
#include <grpc/byte_buffer_reader.h>
#include <grpc/support/port_platform.h>
@ -43,8 +45,8 @@ tsi_result alts_tsi_utils_convert_to_tsi_result(grpc_status_code code) {
grpc_gcp_HandshakerResp* alts_tsi_utils_deserialize_response(
grpc_byte_buffer* resp_buffer, upb_Arena* arena) {
GPR_ASSERT(resp_buffer != nullptr);
GPR_ASSERT(arena != nullptr);
CHECK_NE(resp_buffer, nullptr);
CHECK_NE(arena, nullptr);
grpc_byte_buffer_reader bbr;
grpc_byte_buffer_reader_init(&bbr, resp_buffer);
grpc_slice slice = grpc_byte_buffer_reader_readall(&bbr);

@ -20,6 +20,8 @@
#include <string.h>
#include "absl/log/check.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
@ -142,14 +144,14 @@ static tsi_result alts_grpc_integrity_only_unprotect(
grpc_slice_buffer_reset_and_unref(&rp->header_sb);
grpc_slice_buffer_move_first(protected_slices, rp->header_length,
&rp->header_sb);
GPR_ASSERT(rp->header_sb.length == rp->header_length);
CHECK(rp->header_sb.length == rp->header_length);
iovec_t header_iovec = alts_grpc_record_protocol_get_header_iovec(rp);
// Moves protected slices data to data_sb and leaves the remaining tag.
grpc_slice_buffer_reset_and_unref(&integrity_only_record_protocol->data_sb);
grpc_slice_buffer_move_first(protected_slices,
protected_slices->length - rp->tag_length,
&integrity_only_record_protocol->data_sb);
GPR_ASSERT(protected_slices->length == rp->tag_length);
CHECK(protected_slices->length == rp->tag_length);
iovec_t tag_iovec = {nullptr, rp->tag_length};
if (protected_slices->count == 1) {
tag_iovec.iov_base = GRPC_SLICE_START_PTR(protected_slices->slices[0]);

@ -20,6 +20,8 @@
#include <string.h>
#include "absl/log/check.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
@ -34,7 +36,8 @@ const size_t kInitialIovecBufferSize = 8;
// Makes sure iovec_buf in alts_grpc_record_protocol is large enough.
static void ensure_iovec_buf_size(alts_grpc_record_protocol* rp,
const grpc_slice_buffer* sb) {
GPR_ASSERT(rp != nullptr && sb != nullptr);
CHECK(rp != nullptr);
CHECK_NE(sb, nullptr);
if (sb->count <= rp->iovec_buf_length) {
return;
}
@ -49,7 +52,8 @@ static void ensure_iovec_buf_size(alts_grpc_record_protocol* rp,
void alts_grpc_record_protocol_convert_slice_buffer_to_iovec(
alts_grpc_record_protocol* rp, const grpc_slice_buffer* sb) {
GPR_ASSERT(rp != nullptr && sb != nullptr);
CHECK(rp != nullptr);
CHECK_NE(sb, nullptr);
ensure_iovec_buf_size(rp, sb);
for (size_t i = 0; i < sb->count; i++) {
rp->iovec_buf[i].iov_base = GRPC_SLICE_START_PTR(sb->slices[i]);
@ -59,7 +63,8 @@ void alts_grpc_record_protocol_convert_slice_buffer_to_iovec(
void alts_grpc_record_protocol_copy_slice_buffer(const grpc_slice_buffer* src,
unsigned char* dst) {
GPR_ASSERT(src != nullptr && dst != nullptr);
CHECK(src != nullptr);
CHECK_NE(dst, nullptr);
for (size_t i = 0; i < src->count; i++) {
size_t slice_length = GRPC_SLICE_LENGTH(src->slices[i]);
memcpy(dst, GRPC_SLICE_START_PTR(src->slices[i]), slice_length);

@ -23,6 +23,8 @@
#include <memory>
#include <utility>
#include "absl/log/check.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
@ -84,7 +86,7 @@ static bool read_frame_size(const grpc_slice_buffer* sb,
remaining -= slice_length;
}
}
GPR_ASSERT(remaining == 0);
CHECK_EQ(remaining, 0u);
// Gets little-endian frame size.
uint32_t frame_size = (static_cast<uint32_t>(frame_size_buffer[3]) << 24) |
(static_cast<uint32_t>(frame_size_buffer[2]) << 16) |
@ -294,7 +296,7 @@ tsi_result alts_zero_copy_grpc_protector_create(
impl->max_unprotected_data_size =
alts_grpc_record_protocol_max_unprotected_data_size(
impl->record_protocol, max_protected_frame_size_to_set);
GPR_ASSERT(impl->max_unprotected_data_size > 0);
CHECK_GT(impl->max_unprotected_data_size, 0u);
// Allocates internal slice buffers.
grpc_slice_buffer_init(&impl->unprotected_staging_sb);
grpc_slice_buffer_init(&impl->protected_sb);

@ -21,6 +21,8 @@
#include <stdlib.h>
#include <string.h>
#include "absl/log/check.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
@ -124,7 +126,8 @@ static void store32_little_endian(uint32_t value, unsigned char* buf) {
}
static uint32_t read_frame_size(const grpc_slice_buffer* sb) {
GPR_ASSERT(sb != nullptr && sb->length >= TSI_FAKE_FRAME_HEADER_SIZE);
CHECK(sb != nullptr);
CHECK(sb->length >= TSI_FAKE_FRAME_HEADER_SIZE);
uint8_t frame_size_buffer[TSI_FAKE_FRAME_HEADER_SIZE];
uint8_t* buf = frame_size_buffer;
// Copies the first 4 bytes to a temporary buffer.
@ -141,7 +144,7 @@ static uint32_t read_frame_size(const grpc_slice_buffer* sb) {
remaining -= slice_length;
}
}
GPR_ASSERT(remaining == 0);
CHECK_EQ(remaining, 0u);
return load32_little_endian(frame_size_buffer);
}

@ -16,6 +16,8 @@
#include <map>
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
@ -47,8 +49,8 @@ TlsSessionKeyLoggerCache::TlsSessionKeyLogger::TlsSessionKeyLogger(
grpc_core::RefCountedPtr<TlsSessionKeyLoggerCache> cache)
: tls_session_key_log_file_path_(std::move(tls_session_key_log_file_path)),
cache_(std::move(cache)) {
GPR_ASSERT(!tls_session_key_log_file_path_.empty());
GPR_ASSERT(cache_ != nullptr);
CHECK(!tls_session_key_log_file_path_.empty());
CHECK(cache_ != nullptr);
fd_ = fopen(tls_session_key_log_file_path_.c_str(), "a");
if (fd_ == nullptr) {
grpc_error_handle error = GRPC_OS_ERROR(errno, "fopen");
@ -109,7 +111,7 @@ TlsSessionKeyLoggerCache::~TlsSessionKeyLoggerCache() {
grpc_core::RefCountedPtr<TlsSessionKeyLogger> TlsSessionKeyLoggerCache::Get(
std::string tls_session_key_log_file_path) {
gpr_once_init(&g_cache_mutex_init, do_cache_mutex_init);
GPR_DEBUG_ASSERT(g_tls_session_key_log_cache_mu != nullptr);
DCHECK_NE(g_tls_session_key_log_cache_mu, nullptr);
if (tls_session_key_log_file_path.empty()) {
return nullptr;
}

@ -18,6 +18,8 @@
#include "src/core/tsi/ssl/session_cache/ssl_session_cache.h"
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h>
@ -112,7 +114,7 @@ void SslSessionLRUCache::Put(const char* key, SslSessionPtr session) {
entry_by_key_.emplace(key, node);
AssertInvariants();
if (use_order_list_size_ > capacity_) {
GPR_ASSERT(use_order_list_tail_);
CHECK(use_order_list_tail_);
node = use_order_list_tail_;
Remove(node);
// Order matters, key is destroyed after deleting node.
@ -143,7 +145,7 @@ void SslSessionLRUCache::Remove(SslSessionLRUCache::Node* node) {
} else {
node->next_->prev_ = node->prev_;
}
GPR_ASSERT(use_order_list_size_ >= 1);
CHECK_GE(use_order_list_size_, 1u);
use_order_list_size_--;
}
@ -169,16 +171,16 @@ void SslSessionLRUCache::AssertInvariants() {
Node* current = use_order_list_head_;
while (current != nullptr) {
size++;
GPR_ASSERT(current->prev_ == prev);
CHECK(current->prev_ == prev);
auto it = entry_by_key_.find(current->key());
GPR_ASSERT(it != entry_by_key_.end());
GPR_ASSERT(it->second == current);
CHECK(it != entry_by_key_.end());
CHECK(it->second == current);
prev = current;
current = current->next_;
}
GPR_ASSERT(prev == use_order_list_tail_);
GPR_ASSERT(size == use_order_list_size_);
GPR_ASSERT(entry_by_key_.size() == use_order_list_size_);
CHECK(prev == use_order_list_tail_);
CHECK(size == use_order_list_size_);
CHECK(entry_by_key_.size() == use_order_list_size_);
}
#else
void SslSessionLRUCache::AssertInvariants() {}

@ -15,8 +15,8 @@
// limitations under the License.
//
//
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include "src/core/lib/gprpp/crash.h"
@ -43,11 +43,11 @@ class OpenSslCachedSession : public SslCachedSession {
public:
OpenSslCachedSession(SslSessionPtr session) {
int size = i2d_SSL_SESSION(session.get(), nullptr);
GPR_ASSERT(size > 0);
CHECK_GT(size, 0);
grpc_slice slice = grpc_slice_malloc(size_t(size));
unsigned char* start = GRPC_SLICE_START_PTR(slice);
int second_size = i2d_SSL_SESSION(session.get(), &start);
GPR_ASSERT(size == second_size);
CHECK(size == second_size);
serialized_session_ = slice;
}

@ -45,6 +45,7 @@
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include "absl/log/check.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
@ -194,7 +195,7 @@ static void init_openssl(void) {
#if OPENSSL_VERSION_NUMBER < 0x10100000
if (!CRYPTO_get_locking_callback()) {
int num_locks = CRYPTO_num_locks();
GPR_ASSERT(num_locks > 0);
CHECK_GT(num_locks, 0);
g_openssl_mutexes = static_cast<gpr_mu*>(
gpr_malloc(static_cast<size_t>(num_locks) * sizeof(gpr_mu)));
for (int i = 0; i < num_locks; i++) {
@ -208,15 +209,15 @@ static void init_openssl(void) {
#endif
g_ssl_ctx_ex_factory_index =
SSL_CTX_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr);
GPR_ASSERT(g_ssl_ctx_ex_factory_index != -1);
CHECK_NE(g_ssl_ctx_ex_factory_index, -1);
g_ssl_ctx_ex_crl_provider_index =
SSL_CTX_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr);
GPR_ASSERT(g_ssl_ctx_ex_crl_provider_index != -1);
CHECK_NE(g_ssl_ctx_ex_crl_provider_index, -1);
g_ssl_ex_verified_root_cert_index = SSL_get_ex_new_index(
0, nullptr, nullptr, nullptr, verified_root_cert_free);
GPR_ASSERT(g_ssl_ex_verified_root_cert_index != -1);
CHECK_NE(g_ssl_ex_verified_root_cert_index, -1);
}
// --- Ssl utils. ---
@ -475,7 +476,7 @@ static tsi_result peer_from_x509(X509* cert, int include_certificate_type,
: 0;
size_t property_count;
tsi_result result;
GPR_ASSERT(subject_alt_name_count >= 0);
CHECK_GE(subject_alt_name_count, 0);
property_count = (include_certificate_type ? size_t{1} : 0) +
3 /* subject, common name, certificate */ +
static_cast<size_t>(subject_alt_name_count);
@ -530,7 +531,7 @@ static tsi_result peer_from_x509(X509* cert, int include_certificate_type,
}
if (result != TSI_OK) tsi_peer_destruct(peer);
GPR_ASSERT((int)peer->property_count == current_insert_index);
CHECK((int)peer->property_count == current_insert_index);
return result;
}
@ -541,7 +542,7 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX* context,
tsi_result result = TSI_OK;
X509* certificate = nullptr;
BIO* pem;
GPR_ASSERT(pem_cert_chain_size <= INT_MAX);
CHECK_LE(pem_cert_chain_size, static_cast<size_t>(INT_MAX));
pem = BIO_new_mem_buf(pem_cert_chain, static_cast<int>(pem_cert_chain_size));
if (pem == nullptr) return TSI_OUT_OF_RESOURCES;
@ -661,7 +662,7 @@ static tsi_result ssl_ctx_use_pem_private_key(SSL_CTX* context,
tsi_result result = TSI_OK;
EVP_PKEY* private_key = nullptr;
BIO* pem;
GPR_ASSERT(pem_key_size <= INT_MAX);
CHECK_LE(pem_key_size, static_cast<size_t>(INT_MAX));
pem = BIO_new_mem_buf(pem_key, static_cast<int>(pem_key_size));
if (pem == nullptr) return TSI_OUT_OF_RESOURCES;
do {
@ -706,7 +707,7 @@ static tsi_result x509_store_load_certs(X509_STORE* cert_store,
X509* root = nullptr;
X509_NAME* root_name = nullptr;
BIO* pem;
GPR_ASSERT(pem_roots_size <= INT_MAX);
CHECK_LE(pem_roots_size, static_cast<size_t>(INT_MAX));
pem = BIO_new_mem_buf(pem_roots, static_cast<int>(pem_roots_size));
if (cert_store == nullptr) return TSI_INVALID_ARGUMENT;
if (pem == nullptr) return TSI_OUT_OF_RESOURCES;
@ -1372,7 +1373,7 @@ static tsi_ssl_handshaker_factory_vtable handshaker_factory_vtable = {nullptr};
// allocating memory for the factory.
static void tsi_ssl_handshaker_factory_init(
tsi_ssl_handshaker_factory* factory) {
GPR_ASSERT(factory != nullptr);
CHECK_NE(factory, nullptr);
factory->vtable = &handshaker_factory_vtable;
gpr_ref_init(&factory->refcount, 1);
@ -1600,7 +1601,7 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(
if (error != nullptr) *error = "invalid argument";
return TSI_INVALID_ARGUMENT;
}
GPR_ASSERT(*bytes_size <= INT_MAX);
CHECK_LE(*bytes_size, static_cast<size_t>(INT_MAX));
bytes_read_from_ssl =
BIO_read(impl->network_io, bytes, static_cast<int>(*bytes_size));
if (bytes_read_from_ssl < 0) {
@ -1671,7 +1672,7 @@ static tsi_result ssl_handshaker_process_bytes_from_peer(
if (error != nullptr) *error = "invalid argument";
return TSI_INVALID_ARGUMENT;
}
GPR_ASSERT(*bytes_size <= INT_MAX);
CHECK_LE(*bytes_size, static_cast<size_t>(INT_MAX));
bytes_written_into_ssl_size =
BIO_write(impl->network_io, bytes, static_cast<int>(*bytes_size));
if (bytes_written_into_ssl_size < 0) {
@ -2135,7 +2136,7 @@ static int server_handshaker_factory_npn_advertised_callback(
tsi_ssl_server_handshaker_factory* factory =
static_cast<tsi_ssl_server_handshaker_factory*>(arg);
*out = factory->alpn_protocol_list;
GPR_ASSERT(factory->alpn_protocol_list_length <= UINT_MAX);
CHECK(factory->alpn_protocol_list_length <= UINT_MAX);
*outlen = static_cast<unsigned int>(factory->alpn_protocol_list_length);
return SSL_TLSEXT_ERR_OK;
}
@ -2169,7 +2170,7 @@ static int server_handshaker_factory_new_session_callback(
template <typename T>
static void ssl_keylogging_callback(const SSL* ssl, const char* info) {
SSL_CTX* ssl_context = SSL_get_SSL_CTX(ssl);
GPR_ASSERT(ssl_context != nullptr);
CHECK_NE(ssl_context, nullptr);
void* arg = SSL_CTX_get_ex_data(ssl_context, g_ssl_ctx_ex_factory_index);
T* factory = static_cast<T*>(arg);
factory->key_logger->LogSessionKeys(ssl_context, info);
@ -2303,7 +2304,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options(
break;
}
#if TSI_OPENSSL_ALPN_SUPPORT
GPR_ASSERT(impl->alpn_protocol_list_length < UINT_MAX);
CHECK(impl->alpn_protocol_list_length < UINT_MAX);
if (SSL_CTX_set_alpn_protos(
ssl_context, impl->alpn_protocol_list,
static_cast<unsigned int>(impl->alpn_protocol_list_length))) {
@ -2631,8 +2632,8 @@ int tsi_ssl_peer_matches_name(const tsi_peer* peer, absl::string_view name) {
const tsi_ssl_handshaker_factory_vtable* tsi_ssl_handshaker_factory_swap_vtable(
tsi_ssl_handshaker_factory* factory,
tsi_ssl_handshaker_factory_vtable* new_vtable) {
GPR_ASSERT(factory != nullptr);
GPR_ASSERT(factory->vtable != nullptr);
CHECK_NE(factory, nullptr);
CHECK_NE(factory->vtable, nullptr);
const tsi_ssl_handshaker_factory_vtable* orig_vtable = factory->vtable;
factory->vtable = new_vtable;

@ -23,6 +23,7 @@
#include <openssl/ssl.h>
#include <openssl/x509v3.h>
#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
@ -68,7 +69,7 @@ void LogSslErrorStack(void) {
tsi_result DoSslWrite(SSL* ssl, unsigned char* unprotected_bytes,
size_t unprotected_bytes_size) {
GPR_ASSERT(unprotected_bytes_size <= INT_MAX);
CHECK_LE(unprotected_bytes_size, static_cast<size_t>(INT_MAX));
ERR_clear_error();
int ssl_write_result = SSL_write(ssl, unprotected_bytes,
static_cast<int>(unprotected_bytes_size));
@ -89,7 +90,7 @@ tsi_result DoSslWrite(SSL* ssl, unsigned char* unprotected_bytes,
tsi_result DoSslRead(SSL* ssl, unsigned char* unprotected_bytes,
size_t* unprotected_bytes_size) {
GPR_ASSERT(*unprotected_bytes_size <= INT_MAX);
CHECK_LE(*unprotected_bytes_size, static_cast<size_t>(INT_MAX));
ERR_clear_error();
int read_from_ssl = SSL_read(ssl, unprotected_bytes,
static_cast<int>(*unprotected_bytes_size));
@ -134,7 +135,7 @@ tsi_result SslProtectorProtect(const unsigned char* unprotected_bytes,
int pending_in_ssl = static_cast<int>(BIO_pending(network_io));
if (pending_in_ssl > 0) {
*unprotected_bytes_size = 0;
GPR_ASSERT(*protected_output_frames_size <= INT_MAX);
CHECK_LE(*protected_output_frames_size, static_cast<size_t>(INT_MAX));
read_from_ssl = BIO_read(network_io, protected_output_frames,
static_cast<int>(*protected_output_frames_size));
if (read_from_ssl < 0) {
@ -161,7 +162,7 @@ tsi_result SslProtectorProtect(const unsigned char* unprotected_bytes,
result = DoSslWrite(ssl, buffer, buffer_size);
if (result != TSI_OK) return result;
GPR_ASSERT(*protected_output_frames_size <= INT_MAX);
CHECK_LE(*protected_output_frames_size, static_cast<size_t>(INT_MAX));
read_from_ssl = BIO_read(network_io, protected_output_frames,
static_cast<int>(*protected_output_frames_size));
if (read_from_ssl < 0) {
@ -191,11 +192,11 @@ tsi_result SslProtectorProtectFlush(size_t& buffer_offset,
}
pending = static_cast<int>(BIO_pending(network_io));
GPR_ASSERT(pending >= 0);
CHECK_GE(pending, 0);
*still_pending_size = static_cast<size_t>(pending);
if (*still_pending_size == 0) return TSI_OK;
GPR_ASSERT(*protected_output_frames_size <= INT_MAX);
CHECK_LE(*protected_output_frames_size, static_cast<size_t>(INT_MAX));
read_from_ssl = BIO_read(network_io, protected_output_frames,
static_cast<int>(*protected_output_frames_size));
if (read_from_ssl <= 0) {
@ -204,7 +205,7 @@ tsi_result SslProtectorProtectFlush(size_t& buffer_offset,
}
*protected_output_frames_size = static_cast<size_t>(read_from_ssl);
pending = static_cast<int>(BIO_pending(network_io));
GPR_ASSERT(pending >= 0);
CHECK_GE(pending, 0);
*still_pending_size = static_cast<size_t>(pending);
return TSI_OK;
}
@ -232,7 +233,7 @@ tsi_result SslProtectorUnprotect(const unsigned char* protected_frames_bytes,
*unprotected_bytes_size = output_bytes_size - output_bytes_offset;
// Then, try to write some data to ssl.
GPR_ASSERT(*protected_frames_bytes_size <= INT_MAX);
CHECK_LE(*protected_frames_bytes_size, static_cast<size_t>(INT_MAX));
written_into_ssl = BIO_write(network_io, protected_frames_bytes,
static_cast<int>(*protected_frames_bytes_size));
if (written_into_ssl < 0) {

Loading…
Cancel
Save