Add a way for tests with LeakDetector to free the control plane creds map

pull/19693/head
Alexander Polcyn 5 years ago
parent 6898c23a5d
commit 609107586a
  1. 12
      src/core/lib/security/credentials/credentials.cc
  2. 13
      src/core/lib/security/credentials/credentials.h
  3. 3
      test/core/end2end/fuzzers/client_fuzzer.cc
  4. 3
      test/core/end2end/fuzzers/server_fuzzer.cc
  5. 3
      test/core/security/alts_credentials_fuzzer.cc
  6. 3
      test/core/slice/percent_decode_fuzzer.cc
  7. 3
      test/core/slice/percent_encode_fuzzer.cc

@ -64,6 +64,18 @@ void grpc_control_plane_credentials_init() {
gpr_once_init(&once_init_control_plane_creds, do_control_plane_creds_init);
}
void grpc_test_only_control_plane_credentials_destroy() {
grpc_core::Delete(g_grpc_control_plane_creds);
g_grpc_control_plane_creds = nullptr;
gpr_mu_destroy(&g_control_plane_creds_mu);
}
void grpc_test_only_control_plane_credentials_force_init() {
if (g_grpc_control_plane_creds == nullptr) {
do_control_plane_creds_init();
}
}
bool grpc_channel_credentials_attach_credentials(
grpc_channel_credentials* credentials, const char* authority,
grpc_channel_credentials* control_plane_creds) {

@ -193,6 +193,19 @@ bool grpc_control_plane_credentials_register(
/* Initializes global control plane credentials data. */
void grpc_control_plane_credentials_init();
/* Test only: destroy global control plane credentials data.
* This API is meant for use by a few tests that need to
* satisdy grpc_core::LeakDetector. */
void grpc_test_only_control_plane_credentials_destroy();
/* Test only: force re-initialization of global control
* plane credentials data if it was previously destroyed.
* This API is meant to be used in
* tandem with the
* grpc_test_only_control_plane_credentials_destroy, for
* the few tests that need it. */
void grpc_test_only_control_plane_credentials_force_init();
/* --- grpc_credentials_mdelem_array. --- */
typedef struct {

@ -24,6 +24,7 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/channel.h"
#include "test/core/util/memory_counters.h"
@ -43,6 +44,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (squelch) gpr_set_log_function(dont_log);
grpc_core::testing::LeakDetector leak_detector(leak_check);
grpc_init();
grpc_test_only_control_plane_credentials_force_init();
{
grpc_core::ExecCtx exec_ctx;
grpc_core::Executor::SetThreadingAll(false);
@ -158,6 +160,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
grpc_byte_buffer_destroy(response_payload_recv);
}
}
grpc_test_only_control_plane_credentials_destroy();
grpc_shutdown_blocking();
return 0;
}

@ -20,6 +20,7 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/memory_counters.h"
@ -40,6 +41,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (squelch) gpr_set_log_function(dont_log);
grpc_core::testing::LeakDetector leak_detector(leak_check);
grpc_init();
grpc_test_only_control_plane_credentials_force_init();
{
grpc_core::ExecCtx exec_ctx;
grpc_core::Executor::SetThreadingAll(false);
@ -134,6 +136,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
grpc_server_destroy(server);
grpc_completion_queue_destroy(cq);
}
grpc_test_only_control_plane_credentials_destroy();
grpc_shutdown();
return 0;
}

@ -30,6 +30,7 @@
#include "src/core/lib/security/credentials/alts/alts_credentials.h"
#include "src/core/lib/security/credentials/alts/check_gcp_environment.h"
#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h"
#include "src/core/lib/security/credentials/credentials.h"
using grpc_core::testing::grpc_fuzzer_get_next_byte;
using grpc_core::testing::grpc_fuzzer_get_next_string;
@ -69,6 +70,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
grpc_core::testing::LeakDetector leak_detector(leak_check);
input_stream inp = {data, data + size};
grpc_init();
grpc_test_only_control_plane_credentials_force_init();
bool is_on_gcp = grpc_alts_is_running_on_gcp();
while (inp.cur != inp.end) {
bool enable_untrusted_alts = grpc_fuzzer_get_next_byte(&inp) & 0x01;
@ -107,6 +109,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
}
gpr_free(handshaker_service_url);
}
grpc_test_only_control_plane_credentials_destroy();
grpc_shutdown();
return 0;
}

@ -24,6 +24,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/slice/percent_encoding.h"
#include "test/core/util/memory_counters.h"
@ -33,6 +34,7 @@ bool leak_check = true;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
grpc_core::testing::LeakDetector leak_detector(true);
grpc_init();
grpc_test_only_control_plane_credentials_force_init();
grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size);
grpc_slice output;
if (grpc_strict_percent_decode_slice(
@ -45,6 +47,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
}
grpc_slice_unref(grpc_permissive_percent_decode_slice(input));
grpc_slice_unref(input);
grpc_test_only_control_plane_credentials_destroy();
grpc_shutdown_blocking();
return 0;
}

@ -24,6 +24,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/slice/percent_encoding.h"
#include "test/core/util/memory_counters.h"
@ -33,6 +34,7 @@ bool leak_check = true;
static void test(const uint8_t* data, size_t size, const uint8_t* dict) {
grpc_core::testing::LeakDetector leak_detector(true);
grpc_init();
grpc_test_only_control_plane_credentials_force_init();
grpc_slice input =
grpc_slice_from_copied_buffer(reinterpret_cast<const char*>(data), size);
grpc_slice output = grpc_percent_encode_slice(input, dict);
@ -48,6 +50,7 @@ static void test(const uint8_t* data, size_t size, const uint8_t* dict) {
grpc_slice_unref(output);
grpc_slice_unref(decoded_output);
grpc_slice_unref(permissive_decoded_output);
grpc_test_only_control_plane_credentials_destroy();
grpc_shutdown_blocking();
}

Loading…
Cancel
Save