From 485d77628d0ce8889a420576d5bc41ccbbf48963 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 23 Jan 2015 12:54:05 -0800 Subject: Move string.h to internal code --- src/core/security/credentials.c | 2 +- src/core/security/json_token.c | 2 +- src/core/security/secure_endpoint.c | 2 +- src/core/security/security_context.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/core/security') diff --git a/src/core/security/credentials.c b/src/core/security/credentials.c index 628963e46c..db73c01c1d 100644 --- a/src/core/security/credentials.c +++ b/src/core/security/credentials.c @@ -36,9 +36,9 @@ #include "src/core/httpcli/httpcli.h" #include "src/core/iomgr/iomgr.h" #include "src/core/security/json_token.h" +#include "src/core/support/string.h" #include #include -#include #include #include diff --git a/src/core/security/json_token.c b/src/core/security/json_token.c index 14ee758e8b..82bd9b505a 100644 --- a/src/core/security/json_token.c +++ b/src/core/security/json_token.c @@ -37,9 +37,9 @@ #include #include -#include #include "src/core/security/base64.h" +#include "src/core/support/string.h" #include #include diff --git a/src/core/security/secure_endpoint.c b/src/core/security/secure_endpoint.c index e73767c1aa..9f12cf5d60 100644 --- a/src/core/security/secure_endpoint.c +++ b/src/core/security/secure_endpoint.c @@ -32,11 +32,11 @@ */ #include "src/core/security/secure_endpoint.h" +#include "src/core/support/string.h" #include #include #include #include -#include #include #include "src/core/tsi/transport_security_interface.h" diff --git a/src/core/security/security_context.c b/src/core/security/security_context.c index cce3c7fe04..58cd458415 100644 --- a/src/core/security/security_context.c +++ b/src/core/security/security_context.c @@ -39,12 +39,12 @@ #include "src/core/channel/http_client_filter.h" #include "src/core/security/credentials.h" #include "src/core/security/secure_endpoint.h" +#include "src/core/support/string.h" #include "src/core/surface/lame_client.h" #include "src/core/transport/chttp2/alpn.h" #include #include #include -#include #include "src/core/tsi/fake_transport_security.h" #include "src/core/tsi/ssl_transport_security.h" -- cgit v1.2.3 From 78d241cb3a5c367956a55a2409d5f9dedc86555c Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 23 Jan 2015 13:02:30 -0800 Subject: Remove uses of sprintf --- src/core/security/credentials.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/core/security') diff --git a/src/core/security/credentials.c b/src/core/security/credentials.c index db73c01c1d..b5ff42b337 100644 --- a/src/core/security/credentials.c +++ b/src/core/security/credentials.c @@ -157,7 +157,7 @@ static void ssl_server_destroy(grpc_server_credentials *creds) { if (c->config.pem_private_keys[i] != NULL) { gpr_free(c->config.pem_private_keys[i]); } - if (c->config.pem_cert_chains[i]!= NULL) { + if (c->config.pem_cert_chains[i] != NULL) { gpr_free(c->config.pem_cert_chains[i]); } } @@ -354,7 +354,6 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( cJSON *access_token = NULL; cJSON *token_type = NULL; cJSON *expires_in = NULL; - size_t new_access_token_size = 0; json = cJSON_Parse(null_terminated_body); if (json == NULL) { gpr_log(GPR_ERROR, "Could not parse JSON from %s", null_terminated_body); @@ -384,12 +383,8 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( status = GRPC_CREDENTIALS_ERROR; goto end; } - new_access_token_size = strlen(token_type->valuestring) + 1 + - strlen(access_token->valuestring) + 1; - new_access_token = gpr_malloc(new_access_token_size); - /* C89 does not have snprintf :(. */ - sprintf(new_access_token, "%s %s", token_type->valuestring, - access_token->valuestring); + gpr_asprintf(&new_access_token, "%s %s", token_type->valuestring, + access_token->valuestring); token_lifetime->tv_sec = expires_in->valueint; token_lifetime->tv_nsec = 0; if (*token_elem != NULL) grpc_mdelem_unref(*token_elem); -- cgit v1.2.3 From be6a3550de0b8b0aa82a67e8194f1758287ddce1 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 23 Jan 2015 13:04:45 -0800 Subject: Remove uses of sprintf --- src/core/security/credentials.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/core/security') diff --git a/src/core/security/credentials.c b/src/core/security/credentials.c index b5ff42b337..2f75556e7b 100644 --- a/src/core/security/credentials.c +++ b/src/core/security/credentials.c @@ -534,9 +534,7 @@ static void service_account_fetch_oauth2( response_cb(metadata_req, &response); return; } - body = gpr_malloc(strlen(GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX) + - strlen(jwt) + 1); - sprintf(body, "%s%s", GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX, jwt); + gpr_asprintf(&body, "%s%s", GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX, jwt); memset(&request, 0, sizeof(grpc_httpcli_request)); request.host = GRPC_SERVICE_ACCOUNT_HOST; request.path = GRPC_SERVICE_ACCOUNT_TOKEN_PATH; -- cgit v1.2.3