From ec4bfdfa5748240a9625572aa492bd785a4d4a0b Mon Sep 17 00:00:00 2001 From: Ashitha Santhosh Date: Tue, 17 Dec 2019 16:46:56 -0800 Subject: [PATCH 1/2] Use pointer instead of reference parameter --- .../alts_zero_copy_grpc_protector.cc | 4 ++-- src/core/tsi/transport_security_grpc.cc | 2 +- src/core/tsi/transport_security_grpc.h | 4 ++-- .../alts_zero_copy_grpc_protector_test.cc | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc index af9131477c6..80df2fe1a1f 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc @@ -234,11 +234,11 @@ static void alts_zero_copy_grpc_protector_destroy( } static tsi_result alts_zero_copy_grpc_protector_max_frame_size( - tsi_zero_copy_grpc_protector* self, size_t& max_frame_size) { + tsi_zero_copy_grpc_protector* self, size_t* max_frame_size) { if (self == nullptr) return TSI_INVALID_ARGUMENT; alts_zero_copy_grpc_protector* protector = reinterpret_cast(self); - max_frame_size = protector->max_protected_frame_size; + *max_frame_size = protector->max_protected_frame_size; return TSI_OK; } diff --git a/src/core/tsi/transport_security_grpc.cc b/src/core/tsi/transport_security_grpc.cc index 1364513b529..69591d7343a 100644 --- a/src/core/tsi/transport_security_grpc.cc +++ b/src/core/tsi/transport_security_grpc.cc @@ -66,7 +66,7 @@ void tsi_zero_copy_grpc_protector_destroy(tsi_zero_copy_grpc_protector* self) { } tsi_result tsi_zero_copy_grpc_protector_max_frame_size( - tsi_zero_copy_grpc_protector* self, size_t& max_frame_size) { + tsi_zero_copy_grpc_protector* self, size_t* max_frame_size) { if (self == nullptr) return TSI_INVALID_ARGUMENT; if (self->vtable->max_frame_size == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->max_frame_size(self, max_frame_size); diff --git a/src/core/tsi/transport_security_grpc.h b/src/core/tsi/transport_security_grpc.h index c5829f709fe..d33fa0bd73b 100644 --- a/src/core/tsi/transport_security_grpc.h +++ b/src/core/tsi/transport_security_grpc.h @@ -58,7 +58,7 @@ void tsi_zero_copy_grpc_protector_destroy(tsi_zero_copy_grpc_protector* self); /* Returns value of max protected frame size. Useful for testing. */ tsi_result tsi_zero_copy_grpc_protector_max_frame_size( - tsi_zero_copy_grpc_protector* self, size_t& max_frame_size); + tsi_zero_copy_grpc_protector* self, size_t* max_frame_size); /* Base for tsi_zero_copy_grpc_protector implementations. */ typedef struct { @@ -70,7 +70,7 @@ typedef struct { grpc_slice_buffer* unprotected_slices); void (*destroy)(tsi_zero_copy_grpc_protector* self); tsi_result (*max_frame_size)(tsi_zero_copy_grpc_protector* self, - size_t& max_frame_size); + size_t* max_frame_size); } tsi_zero_copy_grpc_protector_vtable; struct tsi_zero_copy_grpc_protector { diff --git a/test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc b/test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc index 9a426b055b4..59dda1efeaa 100644 --- a/test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc +++ b/test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc @@ -116,14 +116,14 @@ alts_zero_copy_grpc_protector_test_fixture_create(bool rekey, enable_extra_copy, &max_protected_frame_size, &fixture->client) == TSI_OK); GPR_ASSERT(tsi_zero_copy_grpc_protector_max_frame_size( - fixture->client, actual_max_protected_frame_size) == TSI_OK); + fixture->client, &actual_max_protected_frame_size) == TSI_OK); GPR_ASSERT(actual_max_protected_frame_size == max_protected_frame_size); GPR_ASSERT(alts_zero_copy_grpc_protector_create( key, key_length, rekey, /*is_client=*/false, integrity_only, enable_extra_copy, &max_protected_frame_size, &fixture->server) == TSI_OK); GPR_ASSERT(tsi_zero_copy_grpc_protector_max_frame_size( - fixture->server, actual_max_protected_frame_size) == TSI_OK); + fixture->server, &actual_max_protected_frame_size) == TSI_OK); GPR_ASSERT(actual_max_protected_frame_size == max_protected_frame_size); gpr_free(key); grpc_core::ExecCtx::Get()->Flush(); From 0ef0be654182c78865d9a1bd6fd647f50bed2d60 Mon Sep 17 00:00:00 2001 From: Ashitha Santhosh Date: Tue, 17 Dec 2019 17:26:35 -0800 Subject: [PATCH 2/2] Add nullptr check for max_frame_size. --- .../zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc | 2 +- src/core/tsi/transport_security_grpc.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc index 80df2fe1a1f..0cdf97465d0 100644 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc @@ -235,7 +235,7 @@ static void alts_zero_copy_grpc_protector_destroy( static tsi_result alts_zero_copy_grpc_protector_max_frame_size( tsi_zero_copy_grpc_protector* self, size_t* max_frame_size) { - if (self == nullptr) return TSI_INVALID_ARGUMENT; + if (self == nullptr || max_frame_size == nullptr) return TSI_INVALID_ARGUMENT; alts_zero_copy_grpc_protector* protector = reinterpret_cast(self); *max_frame_size = protector->max_protected_frame_size; diff --git a/src/core/tsi/transport_security_grpc.cc b/src/core/tsi/transport_security_grpc.cc index 69591d7343a..cec872690de 100644 --- a/src/core/tsi/transport_security_grpc.cc +++ b/src/core/tsi/transport_security_grpc.cc @@ -67,7 +67,7 @@ void tsi_zero_copy_grpc_protector_destroy(tsi_zero_copy_grpc_protector* self) { tsi_result tsi_zero_copy_grpc_protector_max_frame_size( tsi_zero_copy_grpc_protector* self, size_t* max_frame_size) { - if (self == nullptr) return TSI_INVALID_ARGUMENT; + if (self == nullptr || max_frame_size == nullptr) return TSI_INVALID_ARGUMENT; if (self->vtable->max_frame_size == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->max_frame_size(self, max_frame_size); }