Merge pull request #2143 from murgatroid99/core_security_conversion_warnings

Fixed integer conversion warnings in src/core/security
pull/2184/head
jboeuf 10 years ago
commit bcd1ff2fc3
  1. 10
      src/core/security/base64.c
  2. 14
      src/core/security/secure_endpoint.c
  3. 2
      src/core/security/secure_transport_setup.c
  4. 9
      src/core/security/security_connector.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);

@ -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);
@ -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
@ -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))));
}
}

@ -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);
}

@ -538,7 +538,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) {
@ -577,7 +577,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));
@ -611,7 +611,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) {
@ -630,7 +630,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.",
@ -649,4 +649,3 @@ error:
gpr_free(alpn_protocol_string_lengths);
return GRPC_SECURITY_ERROR;
}

Loading…
Cancel
Save