From e582d09797da2724c1671d3b06f27161517f6c0c Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 19 Jun 2015 12:28:27 -0700 Subject: [PATCH 1/3] Fixed integer conversion warnings in src/core/security --- src/core/security/base64.c | 12 ++++++------ src/core/security/secure_endpoint.c | 16 ++++++++-------- src/core/security/secure_transport_setup.c | 2 +- src/core/security/security_connector.c | 9 ++++----- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/core/security/base64.c b/src/core/security/base64.c index 3b8fea8f737..3a17caa4099 100644 --- a/src/core/security/base64.c +++ b/src/core/security/base64.c @@ -128,7 +128,7 @@ gpr_slice grpc_base64_decode(const char *b64, int url_safe) { size_t num_codes = 0; while (b64_len--) { - unsigned char c = *b64++; + unsigned char c = (unsigned char)(*b64++); signed char code; if (c >= GPR_ARRAY_SIZE(base64_bytes)) continue; if (url_safe) { @@ -149,7 +149,7 @@ gpr_slice grpc_base64_decode(const char *b64, int url_safe) { goto fail; } } else { - codes[num_codes++] = code; + codes[num_codes++] = (unsigned char)code; if (num_codes == 4) { if (codes[0] == GRPC_BASE64_PAD_BYTE || codes[1] == GRPC_BASE64_PAD_BYTE) { @@ -159,7 +159,7 @@ gpr_slice grpc_base64_decode(const char *b64, int url_safe) { if (codes[2] == GRPC_BASE64_PAD_BYTE) { if (codes[3] == GRPC_BASE64_PAD_BYTE) { /* Double padding. */ - gpr_uint32 packed = (codes[0] << 2) | (codes[1] >> 4); + gpr_uint32 packed = (gpr_uint32)((codes[0] << 2) | (codes[1] >> 4)); current[result_size++] = (unsigned char)packed; } else { gpr_log(GPR_ERROR, "Invalid padding detected."); @@ -168,13 +168,13 @@ gpr_slice grpc_base64_decode(const char *b64, int url_safe) { } else if (codes[3] == GRPC_BASE64_PAD_BYTE) { /* Single padding. */ gpr_uint32 packed = - (codes[0] << 10) | (codes[1] << 4) | (codes[2] >> 2); + (gpr_uint32)((codes[0] << 10) | (codes[1] << 4) | (codes[2] >> 2)); current[result_size++] = (unsigned char)(packed >> 8); current[result_size++] = (unsigned char)(packed); } else { /* No padding. */ gpr_uint32 packed = - (codes[0] << 18) | (codes[1] << 12) | (codes[2] << 6) | codes[3]; + (gpr_uint32)((codes[0] << 18) | (codes[1] << 12) | (codes[2] << 6) | codes[3]); current[result_size++] = (unsigned char)(packed >> 16); current[result_size++] = (unsigned char)(packed >> 8); current[result_size++] = (unsigned char)(packed); @@ -189,7 +189,7 @@ gpr_slice grpc_base64_decode(const char *b64, int url_safe) { gpr_slice_unref(result); return gpr_empty_slice(); } - GPR_SLICE_SET_LENGTH(result, result_size); + GPR_SLICE_SET_LENGTH(result, (gpr_uint8)result_size); return result; fail: diff --git a/src/core/security/secure_endpoint.c b/src/core/security/secure_endpoint.c index 7bb1de44132..0489764b4d6 100644 --- a/src/core/security/secure_endpoint.c +++ b/src/core/security/secure_endpoint.c @@ -129,7 +129,7 @@ static void on_read(void *user_data, gpr_slice *slices, size_t nslices, size_t message_size = GPR_SLICE_LENGTH(encrypted); while (message_size > 0 || keep_looping) { - size_t unprotected_buffer_size_written = end - cur; + size_t unprotected_buffer_size_written = (size_t)(end - cur); size_t processed_message_size = message_size; gpr_mu_lock(&ep->protector_mu); result = tsi_frame_protector_unprotect(ep->protector, message_bytes, @@ -166,7 +166,7 @@ static void on_read(void *user_data, gpr_slice *slices, size_t nslices, &ep->input_buffer, gpr_slice_split_head( &ep->read_staging_buffer, - cur - GPR_SLICE_START_PTR(ep->read_staging_buffer))); + (size_t)(cur - GPR_SLICE_START_PTR(ep->read_staging_buffer)))); } /* TODO(yangg) experiment with moving this block after read_cb to see if it @@ -181,9 +181,9 @@ static void on_read(void *user_data, gpr_slice *slices, size_t nslices, return; } /* The upper level will unref the slices. */ - input_buffer_count = ep->input_buffer.count; + input_buffer_count = (int)ep->input_buffer.count; ep->input_buffer.count = 0; - call_read_cb(ep, ep->input_buffer.slices, input_buffer_count, error); + call_read_cb(ep, ep->input_buffer.slices, (size_t)input_buffer_count, error); } static void endpoint_notify_on_read(grpc_endpoint *secure_ep, @@ -225,7 +225,7 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep, grpc_endpoint_write_cb cb, void *user_data) { unsigned i; - int output_buffer_count = 0; + size_t output_buffer_count = 0; tsi_result result = TSI_OK; secure_endpoint *ep = (secure_endpoint *)secure_ep; gpr_uint8 *cur = GPR_SLICE_START_PTR(ep->write_staging_buffer); @@ -248,7 +248,7 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep, gpr_uint8 *message_bytes = GPR_SLICE_START_PTR(plain); size_t message_size = GPR_SLICE_LENGTH(plain); while (message_size > 0) { - size_t protected_buffer_size_to_send = end - cur; + size_t protected_buffer_size_to_send = (size_t)(end - cur); size_t processed_message_size = message_size; gpr_mu_lock(&ep->protector_mu); result = tsi_frame_protector_protect(ep->protector, message_bytes, @@ -273,7 +273,7 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep, if (result == TSI_OK) { size_t still_pending_size; do { - size_t protected_buffer_size_to_send = end - cur; + size_t protected_buffer_size_to_send = (size_t)(end - cur); gpr_mu_lock(&ep->protector_mu); result = tsi_frame_protector_protect_flush(ep->protector, cur, &protected_buffer_size_to_send, @@ -290,7 +290,7 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep, &ep->output_buffer, gpr_slice_split_head( &ep->write_staging_buffer, - cur - GPR_SLICE_START_PTR(ep->write_staging_buffer))); + (size_t)(cur - GPR_SLICE_START_PTR(ep->write_staging_buffer)))); } } diff --git a/src/core/security/secure_transport_setup.c b/src/core/security/secure_transport_setup.c index 3e1db9a12d2..1b39ab141ec 100644 --- a/src/core/security/secure_transport_setup.c +++ b/src/core/security/secure_transport_setup.c @@ -235,7 +235,7 @@ static void on_handshake_data_received_from_peer( gpr_slice_unref(slices[i]); /* split_tail above increments refcount. */ } gpr_slice_buffer_addn(&s->left_overs, &slices[i + 1], - num_left_overs - has_left_overs_in_current_slice); + num_left_overs - (size_t)has_left_overs_in_current_slice); check_peer(s); } diff --git a/src/core/security/security_connector.c b/src/core/security/security_connector.c index 4098636a2eb..4efb800b657 100644 --- a/src/core/security/security_connector.c +++ b/src/core/security/security_connector.c @@ -550,7 +550,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create( alpn_protocol_strings[i] = (const unsigned char *)grpc_chttp2_get_alpn_version_index(i); alpn_protocol_string_lengths[i] = - strlen(grpc_chttp2_get_alpn_version_index(i)); + (unsigned char)strlen(grpc_chttp2_get_alpn_version_index(i)); } if (config == NULL || target_name == NULL) { @@ -589,7 +589,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create( config->pem_private_key, config->pem_private_key_size, config->pem_cert_chain, config->pem_cert_chain_size, pem_root_certs, pem_root_certs_size, ssl_cipher_suites(), alpn_protocol_strings, - alpn_protocol_string_lengths, num_alpn_protocols, &c->handshaker_factory); + alpn_protocol_string_lengths, (uint16_t)num_alpn_protocols, &c->handshaker_factory); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); @@ -623,7 +623,7 @@ grpc_security_status grpc_ssl_server_security_connector_create( alpn_protocol_strings[i] = (const unsigned char *)grpc_chttp2_get_alpn_version_index(i); alpn_protocol_string_lengths[i] = - strlen(grpc_chttp2_get_alpn_version_index(i)); + (unsigned char)strlen(grpc_chttp2_get_alpn_version_index(i)); } if (config == NULL || config->num_key_cert_pairs == 0) { @@ -642,7 +642,7 @@ grpc_security_status grpc_ssl_server_security_connector_create( (const unsigned char **)config->pem_cert_chains, config->pem_cert_chains_sizes, config->num_key_cert_pairs, config->pem_root_certs, config->pem_root_certs_size, ssl_cipher_suites(), - alpn_protocol_strings, alpn_protocol_string_lengths, num_alpn_protocols, + alpn_protocol_strings, alpn_protocol_string_lengths, (uint16_t)num_alpn_protocols, &c->handshaker_factory); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", @@ -661,4 +661,3 @@ error: gpr_free(alpn_protocol_string_lengths); return GRPC_SECURITY_ERROR; } - From 4fca87aee2b2eb07275ebd6e6a6365939d1eb7cf Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 19 Jun 2015 16:15:13 -0700 Subject: [PATCH 2/3] Removed incorrect cast --- src/core/security/base64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/security/base64.c b/src/core/security/base64.c index 3a17caa4099..3f28c09611f 100644 --- a/src/core/security/base64.c +++ b/src/core/security/base64.c @@ -189,7 +189,7 @@ gpr_slice grpc_base64_decode(const char *b64, int url_safe) { gpr_slice_unref(result); return gpr_empty_slice(); } - GPR_SLICE_SET_LENGTH(result, (gpr_uint8)result_size); + GPR_SLICE_SET_LENGTH(result, result_size); return result; fail: From 25c5f2d0f633e3382d649430940ef33adc4abcda Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 22 Jun 2015 09:18:42 -0700 Subject: [PATCH 3/3] Changed input_buffer_count to a size_t --- src/core/security/secure_endpoint.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/security/secure_endpoint.c b/src/core/security/secure_endpoint.c index 0489764b4d6..73496d11538 100644 --- a/src/core/security/secure_endpoint.c +++ b/src/core/security/secure_endpoint.c @@ -116,7 +116,7 @@ static void on_read(void *user_data, gpr_slice *slices, size_t nslices, grpc_endpoint_cb_status error) { unsigned i; gpr_uint8 keep_looping = 0; - int input_buffer_count = 0; + size_t input_buffer_count = 0; tsi_result result = TSI_OK; secure_endpoint *ep = (secure_endpoint *)user_data; gpr_uint8 *cur = GPR_SLICE_START_PTR(ep->read_staging_buffer); @@ -181,9 +181,9 @@ static void on_read(void *user_data, gpr_slice *slices, size_t nslices, return; } /* The upper level will unref the slices. */ - input_buffer_count = (int)ep->input_buffer.count; + input_buffer_count = ep->input_buffer.count; ep->input_buffer.count = 0; - call_read_cb(ep, ep->input_buffer.slices, (size_t)input_buffer_count, error); + call_read_cb(ep, ep->input_buffer.slices, input_buffer_count, error); } static void endpoint_notify_on_read(grpc_endpoint *secure_ep,