Add null input handling in grpc_json_destroy()

pull/17954/head
Juanli Shen 6 years ago
parent e5eb3f8019
commit 1fab48edfc
  1. 5
      src/core/lib/json/json.cc
  2. 2
      src/core/lib/security/credentials/google_default/google_default_credentials.cc
  3. 2
      src/core/lib/security/credentials/jwt/json_token.cc
  4. 4
      src/core/lib/security/credentials/jwt/jwt_verifier.cc
  5. 4
      src/core/lib/security/credentials/oauth2/oauth2_credentials.cc

@ -35,24 +35,21 @@ grpc_json* grpc_json_create(grpc_json_type type) {
} }
void grpc_json_destroy(grpc_json* json) { void grpc_json_destroy(grpc_json* json) {
if (json == nullptr) return;
while (json->child) { while (json->child) {
grpc_json_destroy(json->child); grpc_json_destroy(json->child);
} }
if (json->next) { if (json->next) {
json->next->prev = json->prev; json->next->prev = json->prev;
} }
if (json->prev) { if (json->prev) {
json->prev->next = json->next; json->prev->next = json->next;
} else if (json->parent) { } else if (json->parent) {
json->parent->child = json->next; json->parent->child = json->next;
} }
if (json->owns_value) { if (json->owns_value) {
gpr_free((void*)json->value); gpr_free((void*)json->value);
} }
gpr_free(json); gpr_free(json);
} }

@ -272,7 +272,7 @@ end:
GPR_ASSERT((result == nullptr) + (error == GRPC_ERROR_NONE) == 1); GPR_ASSERT((result == nullptr) + (error == GRPC_ERROR_NONE) == 1);
if (creds_path != nullptr) gpr_free(creds_path); if (creds_path != nullptr) gpr_free(creds_path);
grpc_slice_unref_internal(creds_data); grpc_slice_unref_internal(creds_data);
if (json != nullptr) grpc_json_destroy(json); grpc_json_destroy(json);
*creds = result; *creds = result;
return error; return error;
} }

@ -121,7 +121,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_string(
char* scratchpad = gpr_strdup(json_string); char* scratchpad = gpr_strdup(json_string);
grpc_json* json = grpc_json_parse_string(scratchpad); grpc_json* json = grpc_json_parse_string(scratchpad);
grpc_auth_json_key result = grpc_auth_json_key_create_from_json(json); grpc_auth_json_key result = grpc_auth_json_key_create_from_json(json);
if (json != nullptr) grpc_json_destroy(json); grpc_json_destroy(json);
gpr_free(scratchpad); gpr_free(scratchpad);
return result; return result;
} }

@ -666,7 +666,7 @@ static void on_keys_retrieved(void* user_data, grpc_error* error) {
} }
end: end:
if (json != nullptr) grpc_json_destroy(json); grpc_json_destroy(json);
EVP_PKEY_free(verification_key); EVP_PKEY_free(verification_key);
ctx->user_cb(ctx->user_data, status, claims); ctx->user_cb(ctx->user_data, status, claims);
verifier_cb_ctx_destroy(ctx); verifier_cb_ctx_destroy(ctx);
@ -719,7 +719,7 @@ static void on_openid_config_retrieved(void* user_data, grpc_error* error) {
return; return;
error: error:
if (json != nullptr) grpc_json_destroy(json); grpc_json_destroy(json);
ctx->user_cb(ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, nullptr); ctx->user_cb(ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, nullptr);
verifier_cb_ctx_destroy(ctx); verifier_cb_ctx_destroy(ctx);
} }

@ -80,7 +80,7 @@ grpc_auth_refresh_token grpc_auth_refresh_token_create_from_string(
grpc_json* json = grpc_json_parse_string(scratchpad); grpc_json* json = grpc_json_parse_string(scratchpad);
grpc_auth_refresh_token result = grpc_auth_refresh_token result =
grpc_auth_refresh_token_create_from_json(json); grpc_auth_refresh_token_create_from_json(json);
if (json != nullptr) grpc_json_destroy(json); grpc_json_destroy(json);
gpr_free(scratchpad); gpr_free(scratchpad);
return result; return result;
} }
@ -199,7 +199,7 @@ end:
} }
if (null_terminated_body != nullptr) gpr_free(null_terminated_body); if (null_terminated_body != nullptr) gpr_free(null_terminated_body);
if (new_access_token != nullptr) gpr_free(new_access_token); if (new_access_token != nullptr) gpr_free(new_access_token);
if (json != nullptr) grpc_json_destroy(json); grpc_json_destroy(json);
return status; return status;
} }

Loading…
Cancel
Save