aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-09-10 14:43:18 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-09-10 14:43:18 -0700
commitf96dfc3cf89f0e10a5356ca1bcfd4697410a75c4 (patch)
tree81040d4efce2bb330a213d3ea54ae6e64c3c4870 /src/core
parent0ebfaa04b0cd38ccf273746195ca8c8ac7f7d4d6 (diff)
First round of fixing up implicit 64->32 bit conversions
Diffstat (limited to 'src/core')
-rw-r--r--src/core/channel/channel_args.c2
-rw-r--r--src/core/channel/compress_filter.c3
-rw-r--r--src/core/compression/message_compress.c10
-rw-r--r--src/core/iomgr/alarm.c4
-rw-r--r--src/core/iomgr/alarm_heap.c4
-rw-r--r--src/core/iomgr/tcp_client_posix.c3
-rw-r--r--src/core/iomgr/tcp_server_posix.c7
-rw-r--r--src/core/iomgr/udp_server.c7
-rw-r--r--src/core/iomgr/wakeup_fd_pipe.c2
-rw-r--r--src/core/security/jwt_verifier.c8
-rw-r--r--src/core/support/slice_buffer.c2
-rw-r--r--src/core/support/stack_lockfree.c8
-rw-r--r--src/core/surface/call.c14
-rw-r--r--src/core/surface/server.c13
-rw-r--r--src/core/transport/chttp2/frame_goaway.c6
-rw-r--r--src/core/transport/chttp2/frame_settings.c2
-rw-r--r--src/core/transport/chttp2/hpack_parser.c3
-rw-r--r--src/core/transport/chttp2/parsing.c4
-rw-r--r--src/core/transport/chttp2/stream_encoder.c41
-rw-r--r--src/core/transport/chttp2/timeout_encoding.c2
-rw-r--r--src/core/transport/chttp2/writing.c18
-rw-r--r--src/core/transport/chttp2_transport.c19
-rw-r--r--src/core/transport/transport.h2
-rw-r--r--src/core/tsi/fake_transport_security.c9
-rw-r--r--src/core/tsi/ssl_transport_security.c64
25 files changed, 159 insertions, 98 deletions
diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c
index 31ce3a83fd..591135cd6f 100644
--- a/src/core/channel/channel_args.c
+++ b/src/core/channel/channel_args.c
@@ -132,7 +132,7 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm(
for (i = 0; i < a->num_args; ++i) {
if (a->args[i].type == GRPC_ARG_INTEGER &&
!strcmp(GRPC_COMPRESSION_ALGORITHM_ARG, a->args[i].key)) {
- return a->args[i].value.integer;
+ return (grpc_compression_algorithm)a->args[i].value.integer;
break;
}
}
diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c
index 0b85c7b4fa..8e06094257 100644
--- a/src/core/channel/compress_filter.c
+++ b/src/core/channel/compress_filter.c
@@ -142,8 +142,9 @@ static void finish_compressed_sopb(grpc_stream_op_buffer *send_ops,
grpc_stream_op *sop = &send_ops->ops[i];
switch (sop->type) {
case GRPC_OP_BEGIN_MESSAGE:
+ GPR_ASSERT(calld->slices.length <= GPR_UINT32_MAX);
grpc_sopb_add_begin_message(
- &new_send_ops, calld->slices.length,
+ &new_send_ops, (gpr_uint32)calld->slices.length,
sop->data.begin_message.flags | GRPC_WRITE_INTERNAL_COMPRESS);
break;
case GRPC_OP_SLICE:
diff --git a/src/core/compression/message_compress.c b/src/core/compression/message_compress.c
index 7856f40dd1..01db7134c3 100644
--- a/src/core/compression/message_compress.c
+++ b/src/core/compression/message_compress.c
@@ -49,19 +49,23 @@ static int zlib_body(z_stream *zs, gpr_slice_buffer *input,
int flush;
size_t i;
gpr_slice outbuf = gpr_slice_malloc(OUTPUT_BLOCK_SIZE);
+ const uInt uint_max = ~(uInt)0;
- zs->avail_out = GPR_SLICE_LENGTH(outbuf);
+ GPR_ASSERT(GPR_SLICE_LENGTH(outbuf) <= uint_max);
+ zs->avail_out = (uInt)GPR_SLICE_LENGTH(outbuf);
zs->next_out = GPR_SLICE_START_PTR(outbuf);
flush = Z_NO_FLUSH;
for (i = 0; i < input->count; i++) {
if (i == input->count - 1) flush = Z_FINISH;
- zs->avail_in = GPR_SLICE_LENGTH(input->slices[i]);
+ GPR_ASSERT(GPR_SLICE_LENGTH(input->slices[i]) <= uint_max);
+ zs->avail_in = (uInt)GPR_SLICE_LENGTH(input->slices[i]);
zs->next_in = GPR_SLICE_START_PTR(input->slices[i]);
do {
if (zs->avail_out == 0) {
gpr_slice_buffer_add_indexed(output, outbuf);
outbuf = gpr_slice_malloc(OUTPUT_BLOCK_SIZE);
- zs->avail_out = GPR_SLICE_LENGTH(outbuf);
+ GPR_ASSERT(GPR_SLICE_LENGTH(outbuf) <= uint_max);
+ zs->avail_out = (uInt)GPR_SLICE_LENGTH(outbuf);
zs->next_out = GPR_SLICE_START_PTR(outbuf);
}
r = flate(zs, flush);
diff --git a/src/core/iomgr/alarm.c b/src/core/iomgr/alarm.c
index e31793475f..515b96ffc1 100644
--- a/src/core/iomgr/alarm.c
+++ b/src/core/iomgr/alarm.c
@@ -145,7 +145,7 @@ static void list_remove(grpc_alarm *alarm) {
alarm->prev->next = alarm->next;
}
-static void swap_adjacent_shards_in_queue(size_t first_shard_queue_index) {
+static void swap_adjacent_shards_in_queue(gpr_uint32 first_shard_queue_index) {
shard_type *temp;
temp = g_shard_queue[first_shard_queue_index];
g_shard_queue[first_shard_queue_index] =
@@ -355,7 +355,7 @@ static int run_some_expired_alarms(gpr_mu *drop_mu, gpr_timespec now,
gpr_mu_lock(drop_mu);
}
- return n;
+ return (int)n;
}
int grpc_alarm_check(gpr_mu *drop_mu, gpr_timespec now, gpr_timespec *next) {
diff --git a/src/core/iomgr/alarm_heap.c b/src/core/iomgr/alarm_heap.c
index 7bafdffcef..769142e425 100644
--- a/src/core/iomgr/alarm_heap.c
+++ b/src/core/iomgr/alarm_heap.c
@@ -45,7 +45,7 @@
its argument. */
static void adjust_upwards(grpc_alarm **first, gpr_uint32 i, grpc_alarm *t) {
while (i > 0) {
- gpr_uint32 parent = (i - 1u) / 2u;
+ gpr_uint32 parent = (gpr_uint32)(((int)i - 1) / 2);
if (gpr_time_cmp(first[parent]->deadline, t->deadline) >= 0) break;
first[i] = first[parent];
first[i]->heap_index = i;
@@ -94,7 +94,7 @@ static void maybe_shrink(grpc_alarm_heap *heap) {
static void note_changed_priority(grpc_alarm_heap *heap, grpc_alarm *alarm) {
gpr_uint32 i = alarm->heap_index;
- gpr_uint32 parent = (i - 1u) / 2u;
+ gpr_uint32 parent = (gpr_uint32)(((int)i - 1) / 2);
if (gpr_time_cmp(heap->alarms[parent]->deadline, alarm->deadline) < 0) {
adjust_upwards(heap->alarms, i, alarm);
} else {
diff --git a/src/core/iomgr/tcp_client_posix.c b/src/core/iomgr/tcp_client_posix.c
index 7ca0a60c31..c3668f6a92 100644
--- a/src/core/iomgr/tcp_client_posix.c
+++ b/src/core/iomgr/tcp_client_posix.c
@@ -229,7 +229,8 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep),
}
do {
- err = connect(fd, addr, addr_len);
+ GPR_ASSERT(addr_len < ~(socklen_t)0);
+ err = connect(fd, addr, (socklen_t)addr_len);
} while (err < 0 && errno == EINTR);
addr_str = grpc_sockaddr_to_uri(addr);
diff --git a/src/core/iomgr/tcp_server_posix.c b/src/core/iomgr/tcp_server_posix.c
index 6b81090108..bcbd0afe6b 100644
--- a/src/core/iomgr/tcp_server_posix.c
+++ b/src/core/iomgr/tcp_server_posix.c
@@ -83,7 +83,7 @@ typedef struct {
struct sockaddr sockaddr;
struct sockaddr_un un;
} addr;
- int addr_len;
+ size_t addr_len;
grpc_iomgr_closure read_closure;
grpc_iomgr_closure destroyed_closure;
} server_port;
@@ -236,7 +236,7 @@ static void init_max_accept_queue_size(void) {
char *end;
long i = strtol(buf, &end, 10);
if (i > 0 && i <= INT_MAX && end && *end == 0) {
- n = i;
+ n = (int)i;
}
}
fclose(fp);
@@ -274,7 +274,8 @@ static int prepare_socket(int fd, const struct sockaddr *addr,
goto error;
}
- if (bind(fd, addr, addr_len) < 0) {
+ GPR_ASSERT(addr_len < ~(socklen_t)0);
+ if (bind(fd, addr, (socklen_t)addr_len) < 0) {
char *addr_str;
grpc_sockaddr_to_string(&addr_str, addr, 0);
gpr_log(GPR_ERROR, "bind addr=%s: %s", addr_str, strerror(errno));
diff --git a/src/core/iomgr/udp_server.c b/src/core/iomgr/udp_server.c
index 95ae698781..ed9eee8726 100644
--- a/src/core/iomgr/udp_server.c
+++ b/src/core/iomgr/udp_server.c
@@ -78,7 +78,7 @@ typedef struct {
struct sockaddr sockaddr;
struct sockaddr_un un;
} addr;
- int addr_len;
+ size_t addr_len;
grpc_iomgr_closure read_closure;
grpc_iomgr_closure destroyed_closure;
grpc_udp_server_read_cb read_cb;
@@ -242,7 +242,8 @@ static int prepare_socket(int fd, const struct sockaddr *addr,
#endif
}
- if (bind(fd, addr, addr_len) < 0) {
+ GPR_ASSERT(addr_len < ~(socklen_t)0);
+ if (bind(fd, addr, (socklen_t)addr_len) < 0) {
char *addr_str;
grpc_sockaddr_to_string(&addr_str, addr, 0);
gpr_log(GPR_ERROR, "bind addr=%s: %s", addr_str, strerror(errno));
@@ -431,7 +432,7 @@ void grpc_udp_server_start(grpc_udp_server *s, grpc_pollset **pollsets,
/* TODO(rjshade): Add a test for this method. */
void grpc_udp_server_write(server_port *sp, const char *buffer, size_t buf_len,
const struct sockaddr *peer_address) {
- int rc;
+ ssize_t rc;
rc = sendto(sp->fd, buffer, buf_len, 0, peer_address, sizeof(peer_address));
if (rc < 0) {
gpr_log(GPR_ERROR, "Unable to send data: %s", strerror(errno));
diff --git a/src/core/iomgr/wakeup_fd_pipe.c b/src/core/iomgr/wakeup_fd_pipe.c
index bd643e8061..902034ee4b 100644
--- a/src/core/iomgr/wakeup_fd_pipe.c
+++ b/src/core/iomgr/wakeup_fd_pipe.c
@@ -56,7 +56,7 @@ static void pipe_init(grpc_wakeup_fd *fd_info) {
static void pipe_consume(grpc_wakeup_fd *fd_info) {
char buf[128];
- int r;
+ ssize_t r;
for (;;) {
r = read(fd_info->read_fd, buf, sizeof(buf));
diff --git a/src/core/security/jwt_verifier.c b/src/core/security/jwt_verifier.c
index 03f8c3783e..790f2178db 100644
--- a/src/core/security/jwt_verifier.c
+++ b/src/core/security/jwt_verifier.c
@@ -33,6 +33,7 @@
#include "src/core/security/jwt_verifier.h"
+#include <limits.h>
#include <string.h>
#include "src/core/httpcli/httpcli.h"
@@ -412,7 +413,9 @@ static EVP_PKEY *extract_pkey_from_x509(const char *x509_str) {
X509 *x509 = NULL;
EVP_PKEY *result = NULL;
BIO *bio = BIO_new(BIO_s_mem());
- BIO_write(bio, x509_str, strlen(x509_str));
+ size_t len = strlen(x509_str);
+ GPR_ASSERT(len < INT_MAX);
+ BIO_write(bio, x509_str, (int)len);
x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL);
if (x509 == NULL) {
gpr_log(GPR_ERROR, "Unable to parse x509 cert.");
@@ -439,7 +442,8 @@ static BIGNUM *bignum_from_base64(const char *b64) {
gpr_log(GPR_ERROR, "Invalid base64 for big num.");
return NULL;
}
- result = BN_bin2bn(GPR_SLICE_START_PTR(bin), GPR_SLICE_LENGTH(bin), NULL);
+ result =
+ BN_bin2bn(GPR_SLICE_START_PTR(bin), (int)GPR_SLICE_LENGTH(bin), NULL);
gpr_slice_unref(bin);
return result;
}
diff --git a/src/core/support/slice_buffer.c b/src/core/support/slice_buffer.c
index 6482ef9c9f..8873d459d5 100644
--- a/src/core/support/slice_buffer.c
+++ b/src/core/support/slice_buffer.c
@@ -69,7 +69,7 @@ void gpr_slice_buffer_destroy(gpr_slice_buffer *sb) {
}
}
-gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, unsigned n) {
+gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, size_t n) {
gpr_slice *back;
gpr_uint8 *out;
diff --git a/src/core/support/stack_lockfree.c b/src/core/support/stack_lockfree.c
index 0d4b4bedd9..180ba19c68 100644
--- a/src/core/support/stack_lockfree.c
+++ b/src/core/support/stack_lockfree.c
@@ -123,13 +123,13 @@ int gpr_stack_lockfree_push(gpr_stack_lockfree *stack, int entry) {
#ifndef NDEBUG
/* Check for double push */
{
- int pushed_index = entry / (8 * sizeof(gpr_atm));
- int pushed_bit = entry % (8 * sizeof(gpr_atm));
+ int pushed_index = entry / (int)(8 * sizeof(gpr_atm));
+ int pushed_bit = entry % (int)(8 * sizeof(gpr_atm));
gpr_atm old_val;
old_val = gpr_atm_no_barrier_fetch_add(&stack->pushed[pushed_index],
(gpr_atm)(1UL << pushed_bit));
- GPR_ASSERT((old_val & (1UL << pushed_bit)) == 0);
+ GPR_ASSERT((old_val & (gpr_atm)(1UL << pushed_bit)) == 0);
}
#endif
@@ -167,7 +167,7 @@ int gpr_stack_lockfree_pop(gpr_stack_lockfree *stack) {
old_val = gpr_atm_no_barrier_fetch_add(&stack->pushed[pushed_index],
-(gpr_atm)(1UL << pushed_bit));
- GPR_ASSERT((old_val & (1UL << pushed_bit)) != 0);
+ GPR_ASSERT((old_val & (gpr_atm)(1UL << pushed_bit)) != 0);
}
#endif
diff --git a/src/core/surface/call.c b/src/core/surface/call.c
index 6ece56371b..c96df77a98 100644
--- a/src/core/surface/call.c
+++ b/src/core/surface/call.c
@@ -508,7 +508,7 @@ static void set_status_code(grpc_call *call, status_source source,
if (call->status[source].is_set) return;
call->status[source].is_set = 1;
- call->status[source].code = status;
+ call->status[source].code = (grpc_status_code)status;
call->error_status_set = status != GRPC_STATUS_OK;
if (status != GRPC_STATUS_OK && !grpc_bbq_empty(&call->incoming_queue)) {
@@ -604,7 +604,7 @@ static void unlock(grpc_call *call) {
int completing_requests = 0;
int start_op = 0;
int i;
- const gpr_uint32 MAX_RECV_PEEK_AHEAD = 65536;
+ const size_t MAX_RECV_PEEK_AHEAD = 65536;
size_t buffered_bytes;
int cancel_alarm = 0;
@@ -1107,10 +1107,12 @@ static int fill_send_ops(grpc_call *call, grpc_transport_stream_op *op) {
/* fall through intended */
case WRITE_STATE_STARTED:
if (is_op_live(call, GRPC_IOREQ_SEND_MESSAGE)) {
+ size_t length;
data = call->request_data[GRPC_IOREQ_SEND_MESSAGE];
flags = call->request_flags[GRPC_IOREQ_SEND_MESSAGE];
- grpc_sopb_add_begin_message(
- &call->send_ops, grpc_byte_buffer_length(data.send_message), flags);
+ length = grpc_byte_buffer_length(data.send_message);
+ GPR_ASSERT(length <= GPR_UINT32_MAX);
+ grpc_sopb_add_begin_message(&call->send_ops, (gpr_uint32)length, flags);
copy_byte_buffer_to_stream_ops(data.send_message, &call->send_ops);
op->send_ops = &call->send_ops;
call->last_send_contains |= 1 << GRPC_IOREQ_SEND_MESSAGE;
@@ -1243,7 +1245,7 @@ static grpc_call_error start_ioreq(grpc_call *call, const grpc_ioreq *reqs,
}
if (op == GRPC_IOREQ_SEND_STATUS) {
set_status_code(call, STATUS_FROM_SERVER_STATUS,
- reqs[i].data.send_status.code);
+ (gpr_uint32)reqs[i].data.send_status.code);
if (reqs[i].data.send_status.details) {
set_status_details(call, STATUS_FROM_SERVER_STATUS,
GRPC_MDSTR_REF(reqs[i].data.send_status.details));
@@ -1333,7 +1335,7 @@ static grpc_call_error cancel_with_status(grpc_call *c, grpc_status_code status,
GPR_ASSERT(status != GRPC_STATUS_OK);
- set_status_code(c, STATUS_FROM_API_OVERRIDE, status);
+ set_status_code(c, STATUS_FROM_API_OVERRIDE, (gpr_uint32)status);
set_status_details(c, STATUS_FROM_API_OVERRIDE, details);
c->cancel_with_status = status;
diff --git a/src/core/surface/server.c b/src/core/surface/server.c
index c3d8046787..3d404f78a4 100644
--- a/src/core/surface/server.c
+++ b/src/core/surface/server.c
@@ -33,6 +33,7 @@
#include "src/core/surface/server.h"
+#include <limits.h>
#include <stdlib.h>
#include <string.h>
@@ -804,7 +805,7 @@ grpc_server *grpc_server_create_from_filters(
server->request_freelist =
gpr_stack_lockfree_create(server->max_requested_calls);
for (i = 0; i < (size_t)server->max_requested_calls; i++) {
- gpr_stack_lockfree_push(server->request_freelist, i);
+ gpr_stack_lockfree_push(server->request_freelist, (int)i);
}
request_matcher_init(&server->unregistered_request_matcher,
server->max_requested_calls);
@@ -896,7 +897,7 @@ void grpc_server_setup_transport(grpc_server *s, grpc_transport *transport,
grpc_mdstr *host;
grpc_mdstr *method;
gpr_uint32 hash;
- gpr_uint32 slots;
+ size_t slots;
gpr_uint32 probes;
gpr_uint32 max_probes = 0;
grpc_transport_op op;
@@ -949,7 +950,8 @@ void grpc_server_setup_transport(grpc_server *s, grpc_transport *transport,
crm->host = host;
crm->method = method;
}
- chand->registered_method_slots = slots;
+ GPR_ASSERT(slots <= GPR_UINT32_MAX);
+ chand->registered_method_slots = (gpr_uint32)slots;
chand->registered_method_max_probes = max_probes;
}
@@ -970,7 +972,7 @@ void grpc_server_setup_transport(grpc_server *s, grpc_transport *transport,
op.set_accept_stream_user_data = chand;
op.on_connectivity_state_change = &chand->channel_connectivity_changed;
op.connectivity_state = &chand->connectivity_state;
- op.disconnect = gpr_atm_acq_load(&s->shutdown_flag);
+ op.disconnect = gpr_atm_acq_load(&s->shutdown_flag) != 0;
grpc_transport_perform_op(transport, &op);
}
@@ -1256,8 +1258,9 @@ static void done_request_event(void *req, grpc_cq_completion *c) {
if (rc >= server->requested_calls &&
rc < server->requested_calls + server->max_requested_calls) {
+ GPR_ASSERT(rc - server->requested_calls <= INT_MAX);
gpr_stack_lockfree_push(server->request_freelist,
- rc - server->requested_calls);
+ (int)(rc - server->requested_calls));
} else {
gpr_free(req);
}
diff --git a/src/core/transport/chttp2/frame_goaway.c b/src/core/transport/chttp2/frame_goaway.c
index d40e6fd03a..1a6d80da58 100644
--- a/src/core/transport/chttp2/frame_goaway.c
+++ b/src/core/transport/chttp2/frame_goaway.c
@@ -143,7 +143,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
transport_parsing->goaway_received = 1;
transport_parsing->goaway_last_stream_index = p->last_stream_id;
gpr_slice_unref(transport_parsing->goaway_text);
- transport_parsing->goaway_error = p->error_code;
+ transport_parsing->goaway_error = (grpc_status_code)p->error_code;
transport_parsing->goaway_text =
gpr_slice_new(p->debug_data, p->debug_length, gpr_free);
p->debug_data = NULL;
@@ -160,7 +160,9 @@ void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code,
gpr_slice_buffer *slice_buffer) {
gpr_slice header = gpr_slice_malloc(9 + 4 + 4);
gpr_uint8 *p = GPR_SLICE_START_PTR(header);
- gpr_uint32 frame_length = 4 + 4 + GPR_SLICE_LENGTH(debug_data);
+ gpr_uint32 frame_length;
+ GPR_ASSERT(GPR_SLICE_LENGTH(debug_data) < GPR_UINT32_MAX - 4 - 4);
+ frame_length = 4 + 4 + (gpr_uint32)GPR_SLICE_LENGTH(debug_data);
/* frame header: length */
*p++ = frame_length >> 16;
diff --git a/src/core/transport/chttp2/frame_settings.c b/src/core/transport/chttp2/frame_settings.c
index 927ae55996..f70776bf4c 100644
--- a/src/core/transport/chttp2/frame_settings.c
+++ b/src/core/transport/chttp2/frame_settings.c
@@ -76,7 +76,7 @@ static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length,
gpr_slice grpc_chttp2_settings_create(gpr_uint32 *old, const gpr_uint32 *new,
gpr_uint32 force_mask, size_t count) {
size_t i;
- size_t n = 0;
+ gpr_uint32 n = 0;
gpr_slice output;
gpr_uint8 *p;
diff --git a/src/core/transport/chttp2/hpack_parser.c b/src/core/transport/chttp2/hpack_parser.c
index f806f59ed7..93a452f1fd 100644
--- a/src/core/transport/chttp2/hpack_parser.c
+++ b/src/core/transport/chttp2/hpack_parser.c
@@ -1085,7 +1085,8 @@ static int parse_string_prefix(grpc_chttp2_hpack_parser *p,
static void append_bytes(grpc_chttp2_hpack_parser_string *str,
const gpr_uint8 *data, size_t length) {
if (length + str->length > str->capacity) {
- str->capacity = str->length + length;
+ GPR_ASSERT(str->length + length <= GPR_UINT32_MAX);
+ str->capacity = (gpr_uint32)(str->length + length);
str->str = gpr_realloc(str->str, str->capacity);
}
memcpy(str->str + str->length, data, length);
diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c
index b0f884e258..a29987a05a 100644
--- a/src/core/transport/chttp2/parsing.c
+++ b/src/core/transport/chttp2/parsing.c
@@ -131,7 +131,7 @@ void grpc_chttp2_publish_reads(
published later */
if (transport_parsing->goaway_received) {
grpc_chttp2_add_incoming_goaway(transport_global,
- transport_parsing->goaway_error,
+ (gpr_uint32)transport_parsing->goaway_error,
transport_parsing->goaway_text);
transport_parsing->goaway_text = gpr_empty_slice();
transport_parsing->goaway_received = 0;
@@ -212,7 +212,7 @@ void grpc_chttp2_publish_reads(
if (stream_parsing->saw_rst_stream) {
stream_global->cancelled = 1;
stream_global->cancelled_status = grpc_chttp2_http2_error_to_grpc_status(
- stream_parsing->rst_stream_reason);
+ (grpc_chttp2_error_code)stream_parsing->rst_stream_reason);
if (stream_parsing->rst_stream_reason == GRPC_CHTTP2_NO_ERROR) {
stream_global->published_cancelled = 1;
}
diff --git a/src/core/transport/chttp2/stream_encoder.c b/src/core/transport/chttp2/stream_encoder.c
index bcae93dc7a..8c30af652f 100644
--- a/src/core/transport/chttp2/stream_encoder.c
+++ b/src/core/transport/chttp2/stream_encoder.c
@@ -74,8 +74,9 @@ typedef struct {
} framer_state;
/* fills p (which is expected to be 9 bytes long) with a data frame header */
-static void fill_header(gpr_uint8 *p, gpr_uint8 type, gpr_uint32 id,
- gpr_uint32 len, gpr_uint8 flags) {
+static void fill_header(gpr_uint8 *p, gpr_uint8 type, gpr_uint32 id, size_t len,
+ gpr_uint8 flags) {
+ GPR_ASSERT(len < 16777316);
*p++ = len >> 16;
*p++ = len >> 8;
*p++ = len;
@@ -185,8 +186,8 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c,
gpr_uint32 key_hash = elem->key->hash;
gpr_uint32 elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash);
gpr_uint32 new_index = c->tail_remote_index + c->table_elems + 1;
- gpr_uint32 elem_size = 32 + GPR_SLICE_LENGTH(elem->key->slice) +
- GPR_SLICE_LENGTH(elem->value->slice);
+ size_t elem_size = 32 + GPR_SLICE_LENGTH(elem->key->slice) +
+ GPR_SLICE_LENGTH(elem->value->slice);
grpc_mdelem *elem_to_unref;
/* Reserve space for this element in the remote table: if this overflows
@@ -270,7 +271,7 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c,
static void emit_indexed(grpc_chttp2_hpack_compressor *c, gpr_uint32 index,
framer_state *st) {
- size_t len = GRPC_CHTTP2_VARINT_LENGTH(index, 1);
+ gpr_uint32 len = GRPC_CHTTP2_VARINT_LENGTH(index, 1);
GRPC_CHTTP2_WRITE_VARINT(index, 1, 0x80, add_tiny_header_data(st, len), len);
}
@@ -291,11 +292,13 @@ static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c,
gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2);
gpr_uint8 huffman_prefix;
gpr_slice value_slice = get_wire_value(elem, &huffman_prefix);
- gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice);
- gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
+ size_t len_val = GPR_SLICE_LENGTH(value_slice);
+ gpr_uint32 len_val_len;
+ GPR_ASSERT(len_val <= GPR_UINT32_MAX);
+ len_val_len = GRPC_CHTTP2_VARINT_LENGTH((gpr_uint32)len_val, 1);
GRPC_CHTTP2_WRITE_VARINT(key_index, 2, 0x40,
add_tiny_header_data(st, len_pfx), len_pfx);
- GRPC_CHTTP2_WRITE_VARINT(len_val, 1, 0x00,
+ GRPC_CHTTP2_WRITE_VARINT((gpr_uint32)len_val, 1, 0x00,
add_tiny_header_data(st, len_val_len), len_val_len);
add_header_data(st, gpr_slice_ref(value_slice));
}
@@ -306,23 +309,27 @@ static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c,
gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4);
gpr_uint8 huffman_prefix;
gpr_slice value_slice = get_wire_value(elem, &huffman_prefix);
- gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice);
- gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
+ size_t len_val = GPR_SLICE_LENGTH(value_slice);
+ gpr_uint32 len_val_len;
+ GPR_ASSERT(len_val <= GPR_UINT32_MAX);
+ len_val_len = GRPC_CHTTP2_VARINT_LENGTH((gpr_uint32)len_val, 1);
GRPC_CHTTP2_WRITE_VARINT(key_index, 4, 0x00,
add_tiny_header_data(st, len_pfx), len_pfx);
- GRPC_CHTTP2_WRITE_VARINT(len_val, 1, 0x00,
+ GRPC_CHTTP2_WRITE_VARINT((gpr_uint32)len_val, 1, 0x00,
add_tiny_header_data(st, len_val_len), len_val_len);
add_header_data(st, gpr_slice_ref(value_slice));
}
static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c,
grpc_mdelem *elem, framer_state *st) {
- gpr_uint32 len_key = GPR_SLICE_LENGTH(elem->key->slice);
+ gpr_uint32 len_key = (gpr_uint32)GPR_SLICE_LENGTH(elem->key->slice);
gpr_uint8 huffman_prefix;
gpr_slice value_slice = get_wire_value(elem, &huffman_prefix);
- gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice);
+ gpr_uint32 len_val = (gpr_uint32)GPR_SLICE_LENGTH(value_slice);
gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1);
gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
+ GPR_ASSERT(len_key <= GPR_UINT32_MAX);
+ GPR_ASSERT(GPR_SLICE_LENGTH(value_slice) <= GPR_UINT32_MAX);
*add_tiny_header_data(st, 1) = 0x40;
GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00,
add_tiny_header_data(st, len_key_len), len_key_len);
@@ -334,12 +341,14 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c,
static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c,
grpc_mdelem *elem, framer_state *st) {
- gpr_uint32 len_key = GPR_SLICE_LENGTH(elem->key->slice);
+ gpr_uint32 len_key = (gpr_uint32)GPR_SLICE_LENGTH(elem->key->slice);
gpr_uint8 huffman_prefix;
gpr_slice value_slice = get_wire_value(elem, &huffman_prefix);
- gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice);
+ gpr_uint32 len_val = (gpr_uint32)GPR_SLICE_LENGTH(value_slice);
gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1);
gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
+ GPR_ASSERT(len_key <= GPR_UINT32_MAX);
+ GPR_ASSERT(GPR_SLICE_LENGTH(value_slice) <= GPR_UINT32_MAX);
*add_tiny_header_data(st, 1) = 0x00;
GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00,
add_tiny_header_data(st, len_key_len), len_key_len);
@@ -565,7 +574,7 @@ void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof,
framer_state st;
gpr_slice slice;
grpc_stream_op *op;
- gpr_uint32 max_take_size;
+ size_t max_take_size;
gpr_uint32 curop = 0;
gpr_uint32 unref_op;
grpc_mdctx *mdctx = compressor->mdctx;
diff --git a/src/core/transport/chttp2/timeout_encoding.c b/src/core/transport/chttp2/timeout_encoding.c
index 40fcdc26dc..8a9b290ecb 100644
--- a/src/core/transport/chttp2/timeout_encoding.c
+++ b/src/core/transport/chttp2/timeout_encoding.c
@@ -123,7 +123,7 @@ void grpc_chttp2_encode_timeout(gpr_timespec timeout, char *buffer) {
enc_nanos(buffer, timeout.tv_nsec);
} else if (timeout.tv_sec < 1000 && timeout.tv_nsec != 0) {
enc_micros(buffer,
- timeout.tv_sec * 1000000 +
+ (int)(timeout.tv_sec * 1000000) +
(timeout.tv_nsec / 1000 + (timeout.tv_nsec % 1000 != 0)));
} else {
enc_seconds(buffer, timeout.tv_sec + (timeout.tv_nsec != 0));
diff --git a/src/core/transport/chttp2/writing.c b/src/core/transport/chttp2/writing.c
index ac79044e08..c015e82931 100644
--- a/src/core/transport/chttp2/writing.c
+++ b/src/core/transport/chttp2/writing.c
@@ -32,10 +32,13 @@
*/
#include "src/core/transport/chttp2/internal.h"
-#include "src/core/transport/chttp2/http2_errors.h"
+
+#include <limits.h>
#include <grpc/support/log.h>
+#include "src/core/transport/chttp2/http2_errors.h"
+
static void finalize_outbuf(grpc_chttp2_transport_writing *transport_writing);
int grpc_chttp2_unlocking_check_writes(
@@ -78,12 +81,13 @@ int grpc_chttp2_unlocking_check_writes(
stream_writing->send_closed = GRPC_DONT_SEND_CLOSED;
if (stream_global->outgoing_sopb) {
- window_delta =
- grpc_chttp2_preencode(stream_global->outgoing_sopb->ops,
- &stream_global->outgoing_sopb->nops,
- GPR_MIN(transport_global->outgoing_window,
- stream_global->outgoing_window),
- &stream_writing->sopb);
+ window_delta = grpc_chttp2_preencode(
+ stream_global->outgoing_sopb->ops,
+ &stream_global->outgoing_sopb->nops,
+ (gpr_uint32)GPR_MIN(GPR_MIN(transport_global->outgoing_window,
+ stream_global->outgoing_window),
+ GPR_UINT32_MAX),
+ &stream_writing->sopb);
GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(
"write", transport_global, outgoing_window, -(gpr_int64)window_delta);
GRPC_CHTTP2_FLOWCTL_TRACE_STREAM("write", transport_global, stream_global,
diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c
index c1a3c0436f..c80330527e 100644
--- a/src/core/transport/chttp2_transport.c
+++ b/src/core/transport/chttp2_transport.c
@@ -692,7 +692,8 @@ static void perform_stream_op_locked(
op->max_recv_bytes - stream_global->max_recv_bytes);
stream_global->unannounced_incoming_window +=
op->max_recv_bytes - stream_global->max_recv_bytes;
- stream_global->max_recv_bytes = op->max_recv_bytes;
+ stream_global->max_recv_bytes =
+ (gpr_uint32)(GPR_MIN(op->max_recv_bytes, GPR_UINT32_MAX));
}
grpc_chttp2_incoming_metadata_live_op_buffer_end(
&stream_global->outstanding_metadata);
@@ -761,7 +762,7 @@ static void perform_transport_op(grpc_transport *gt, grpc_transport_op *op) {
t->global.sent_goaway = 1;
grpc_chttp2_goaway_append(
t->global.last_incoming_stream_id,
- grpc_chttp2_grpc_status_to_http2_error(op->goaway_status),
+ (gpr_uint32)grpc_chttp2_grpc_status_to_http2_error(op->goaway_status),
gpr_slice_ref(*op->goaway_message), &t->global.qbuf);
close_transport = !grpc_chttp2_has_streams(t);
}
@@ -829,8 +830,9 @@ static void remove_stream(grpc_chttp2_transport *t, gpr_uint32 id) {
new_stream_count = grpc_chttp2_stream_map_size(&t->parsing_stream_map) +
grpc_chttp2_stream_map_size(&t->new_stream_map);
+ GPR_ASSERT(new_stream_count <= GPR_UINT32_MAX);
if (new_stream_count != t->global.concurrent_stream_count) {
- t->global.concurrent_stream_count = new_stream_count;
+ t->global.concurrent_stream_count = (gpr_uint32)new_stream_count;
maybe_start_some_streams(&t->global);
}
}
@@ -943,7 +945,8 @@ static void cancel_from_api(grpc_chttp2_transport_global *transport_global,
gpr_slice_buffer_add(
&transport_global->qbuf,
grpc_chttp2_rst_stream_create(
- stream_global->id, grpc_chttp2_grpc_status_to_http2_error(status)));
+ stream_global->id,
+ (gpr_uint32)grpc_chttp2_grpc_status_to_http2_error(status)));
}
grpc_chttp2_list_add_read_write_state_changed(transport_global,
stream_global);
@@ -989,11 +992,11 @@ static void close_from_api(grpc_chttp2_transport_global *transport_global,
*p++ = 's';
if (status < 10) {
*p++ = 1;
- *p++ = '0' + status;
+ *p++ = (gpr_uint8)('0' + status);
} else {
*p++ = 2;
- *p++ = '0' + (status / 10);
- *p++ = '0' + (status % 10);
+ *p++ = (gpr_uint8)('0' + (status / 10));
+ *p++ = (gpr_uint8)('0' + (status % 10));
}
GPR_ASSERT(p == GPR_SLICE_END_PTR(status_hdr));
len += GPR_SLICE_LENGTH(status_hdr);
@@ -1121,7 +1124,7 @@ static int recv_data_loop(grpc_chttp2_transport *t, int *success) {
grpc_chttp2_stream_map_move_into(&t->new_stream_map,
&t->parsing_stream_map);
t->global.concurrent_stream_count =
- grpc_chttp2_stream_map_size(&t->parsing_stream_map);
+ (gpr_uint32)grpc_chttp2_stream_map_size(&t->parsing_stream_map);
if (t->parsing.initial_window_update != 0) {
grpc_chttp2_stream_map_for_each(&t->parsing_stream_map,
update_global_window, t);
diff --git a/src/core/transport/transport.h b/src/core/transport/transport.h
index 92c1f38c5e..6e1ec2f64c 100644
--- a/src/core/transport/transport.h
+++ b/src/core/transport/transport.h
@@ -75,7 +75,7 @@ typedef struct grpc_transport_stream_op {
/** The number of bytes this peer is currently prepared to receive.
These bytes will be eventually used to replenish per-stream flow control
windows. */
- gpr_uint32 max_recv_bytes;
+ size_t max_recv_bytes;
grpc_iomgr_closure *on_done_recv;
grpc_pollset *bind_pollset;
diff --git a/src/core/tsi/fake_transport_security.c b/src/core/tsi/fake_transport_security.c
index a813c30221..b1a975155a 100644
--- a/src/core/tsi/fake_transport_security.c
+++ b/src/core/tsi/fake_transport_security.c
@@ -100,7 +100,7 @@ static const char* tsi_fake_handshake_message_to_string(int msg) {
static tsi_result tsi_fake_handshake_message_from_string(
const char* msg_string, tsi_fake_handshake_message* msg) {
- int i;
+ tsi_fake_handshake_message i;
for (i = 0; i < TSI_FAKE_HANDSHAKE_MESSAGE_MAX; i++) {
if (strncmp(msg_string, tsi_fake_handshake_message_strings[i],
strlen(tsi_fake_handshake_message_strings[i])) == 0) {
@@ -219,7 +219,7 @@ static tsi_result bytes_to_frame(unsigned char* bytes, size_t bytes_size,
frame->offset = 0;
frame->size = bytes_size + TSI_FAKE_FRAME_HEADER_SIZE;
if (!tsi_fake_frame_ensure_size(frame)) return TSI_OUT_OF_RESOURCES;
- store32_little_endian(frame->size, frame->data);
+ store32_little_endian((gpr_uint32)frame->size, frame->data);
memcpy(frame->data + TSI_FAKE_FRAME_HEADER_SIZE, bytes, bytes_size);
tsi_fake_frame_reset(frame, 1 /* needs draining */);
return TSI_OK;
@@ -266,7 +266,7 @@ static tsi_result fake_protector_protect(tsi_frame_protector* self,
if (frame->size == 0) {
/* New frame, create a header. */
size_t written_in_frame_size = 0;
- store32_little_endian(impl->max_frame_size, frame_header);
+ store32_little_endian((gpr_uint32)impl->max_frame_size, frame_header);
written_in_frame_size = TSI_FAKE_FRAME_HEADER_SIZE;
result = fill_frame_from_bytes(frame_header, &written_in_frame_size, frame);
if (result != TSI_INCOMPLETE_DATA) {
@@ -303,7 +303,8 @@ static tsi_result fake_protector_protect_flush(
frame->size = frame->offset;
frame->offset = 0;
frame->needs_draining = 1;
- store32_little_endian(frame->size, frame->data); /* Overwrite header. */
+ store32_little_endian((gpr_uint32)frame->size,
+ frame->data); /* Overwrite header. */
}
result = drain_frame_to_bytes(protected_output_frames,
protected_output_frames_size, frame);
diff --git a/src/core/tsi/ssl_transport_security.c b/src/core/tsi/ssl_transport_security.c
index 6add492865..99ce7ecadf 100644
--- a/src/core/tsi/ssl_transport_security.c
+++ b/src/core/tsi/ssl_transport_security.c
@@ -291,7 +291,7 @@ static tsi_result add_subject_alt_names_properties_to_peer(
for (i = 0; i < subject_alt_name_count; i++) {
GENERAL_NAME* subject_alt_name =
- sk_GENERAL_NAME_value(subject_alt_names, i);
+ sk_GENERAL_NAME_value(subject_alt_names, (int)i);
/* Filter out the non-dns entries names. */
if (subject_alt_name->type == GEN_DNS) {
unsigned char* dns_name = NULL;
@@ -366,7 +366,10 @@ static void log_ssl_error_stack(void) {
/* Performs an SSL_read and handle errors. */
static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes,
size_t* unprotected_bytes_size) {
- int read_from_ssl = SSL_read(ssl, unprotected_bytes, *unprotected_bytes_size);
+ int read_from_ssl;
+ GPR_ASSERT(*unprotected_bytes_size <= INT_MAX);
+ read_from_ssl =
+ SSL_read(ssl, unprotected_bytes, (int)*unprotected_bytes_size);
if (read_from_ssl == 0) {
gpr_log(GPR_ERROR, "SSL_read returned 0 unexpectedly.");
return TSI_INTERNAL_ERROR;
@@ -400,8 +403,10 @@ static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes,
/* Performs an SSL_write and handle errors. */
static tsi_result do_ssl_write(SSL* ssl, unsigned char* unprotected_bytes,
size_t unprotected_bytes_size) {
- int ssl_write_result =
- SSL_write(ssl, unprotected_bytes, unprotected_bytes_size);
+ int ssl_write_result;
+ GPR_ASSERT(unprotected_bytes_size <= INT_MAX);
+ ssl_write_result =
+ SSL_write(ssl, unprotected_bytes, (int)unprotected_bytes_size);
if (ssl_write_result < 0) {
ssl_write_result = SSL_get_error(ssl, ssl_write_result);
if (ssl_write_result == SSL_ERROR_WANT_READ) {
@@ -423,7 +428,9 @@ static tsi_result ssl_ctx_use_certificate_chain(
size_t pem_cert_chain_size) {
tsi_result result = TSI_OK;
X509* certificate = NULL;
- BIO* pem = BIO_new_mem_buf((void*)pem_cert_chain, pem_cert_chain_size);
+ BIO* pem;
+ GPR_ASSERT(pem_cert_chain_size <= INT_MAX);
+ pem = BIO_new_mem_buf((void*)pem_cert_chain, (int)pem_cert_chain_size);
if (pem == NULL) return TSI_OUT_OF_RESOURCES;
do {
@@ -464,7 +471,9 @@ static tsi_result ssl_ctx_use_private_key(SSL_CTX* context,
size_t pem_key_size) {
tsi_result result = TSI_OK;
EVP_PKEY* private_key = NULL;
- BIO* pem = BIO_new_mem_buf((void*)pem_key, pem_key_size);
+ BIO* pem;
+ GPR_ASSERT(pem_key_size <= INT_MAX);
+ pem = BIO_new_mem_buf((void*)pem_key, (int)pem_key_size);
if (pem == NULL) return TSI_OUT_OF_RESOURCES;
do {
private_key = PEM_read_bio_PrivateKey(pem, NULL, NULL, "");
@@ -491,8 +500,11 @@ static tsi_result ssl_ctx_load_verification_certs(
size_t num_roots = 0;
X509* root = NULL;
X509_NAME* root_name = NULL;
- BIO* pem = BIO_new_mem_buf((void*)pem_roots, pem_roots_size);
- X509_STORE* root_store = SSL_CTX_get_cert_store(context);
+ BIO* pem;
+ X509_STORE* root_store;
+ GPR_ASSERT(pem_roots_size <= INT_MAX);
+ pem = BIO_new_mem_buf((void*)pem_roots, (int)pem_roots_size);
+ root_store = SSL_CTX_get_cert_store(context);
if (root_store == NULL) return TSI_INVALID_ARGUMENT;
if (pem == NULL) return TSI_OUT_OF_RESOURCES;
if (root_names != NULL) {
@@ -592,7 +604,9 @@ static tsi_result extract_x509_subject_names_from_pem_cert(
const unsigned char* pem_cert, size_t pem_cert_size, tsi_peer* peer) {
tsi_result result = TSI_OK;
X509* cert = NULL;
- BIO* pem = BIO_new_mem_buf((void*)pem_cert, pem_cert_size);
+ BIO* pem;
+ GPR_ASSERT(pem_cert_size <= INT_MAX);
+ pem = BIO_new_mem_buf((void*)pem_cert, (int)pem_cert_size);
if (pem == NULL) return TSI_OUT_OF_RESOURCES;
cert = PEM_read_bio_X509(pem, NULL, NULL, "");
@@ -657,8 +671,9 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self,
int pending_in_ssl = BIO_pending(impl->from_ssl);
if (pending_in_ssl > 0) {
*unprotected_bytes_size = 0;
+ GPR_ASSERT(*protected_output_frames_size <= INT_MAX);
read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames,
- *protected_output_frames_size);
+ (int)*protected_output_frames_size);
if (read_from_ssl < 0) {
gpr_log(GPR_ERROR,
"Could not read from BIO even though some data is pending");
@@ -684,8 +699,9 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self,
result = do_ssl_write(impl->ssl, impl->buffer, impl->buffer_size);
if (result != TSI_OK) return result;
+ GPR_ASSERT(*protected_output_frames_size <= INT_MAX);
read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames,
- *protected_output_frames_size);
+ (int)*protected_output_frames_size);
if (read_from_ssl < 0) {
gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write.");
return TSI_INTERNAL_ERROR;
@@ -715,8 +731,9 @@ static tsi_result ssl_protector_protect_flush(
*still_pending_size = (size_t)pending;
if (*still_pending_size == 0) return TSI_OK;
+ GPR_ASSERT(*protected_output_frames_size <= INT_MAX);
read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames,
- *protected_output_frames_size);
+ (int)*protected_output_frames_size);
if (read_from_ssl <= 0) {
gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write.");
return TSI_INTERNAL_ERROR;
@@ -751,8 +768,9 @@ static tsi_result ssl_protector_unprotect(
*unprotected_bytes_size = output_bytes_size - output_bytes_offset;
/* Then, try to write some data to ssl. */
+ GPR_ASSERT(*protected_frames_bytes_size <= INT_MAX);
written_into_ssl = BIO_write(impl->into_ssl, protected_frames_bytes,
- *protected_frames_bytes_size);
+ (int)*protected_frames_bytes_size);
if (written_into_ssl < 0) {
gpr_log(GPR_ERROR, "Sending protected frame to ssl failed with %d",
written_into_ssl);
@@ -792,7 +810,8 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self,
*bytes_size > INT_MAX) {
return TSI_INVALID_ARGUMENT;
}
- bytes_read_from_ssl = BIO_read(impl->from_ssl, bytes, *bytes_size);
+ GPR_ASSERT(*bytes_size <= INT_MAX);
+ bytes_read_from_ssl = BIO_read(impl->from_ssl, bytes, (int)*bytes_size);
if (bytes_read_from_ssl < 0) {
*bytes_size = 0;
if (!BIO_should_retry(impl->from_ssl)) {
@@ -822,7 +841,9 @@ static tsi_result ssl_handshaker_process_bytes_from_peer(
if (bytes == NULL || bytes_size == 0 || *bytes_size > INT_MAX) {
return TSI_INVALID_ARGUMENT;
}
- bytes_written_into_ssl_size = BIO_write(impl->into_ssl, bytes, *bytes_size);
+ GPR_ASSERT(*bytes_size <= INT_MAX);
+ bytes_written_into_ssl_size =
+ BIO_write(impl->into_ssl, bytes, (int)*bytes_size);
if (bytes_written_into_ssl_size < 0) {
gpr_log(GPR_ERROR, "Could not write to memory BIO.");
impl->result = TSI_INTERNAL_ERROR;
@@ -1044,9 +1065,9 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client,
static int select_protocol_list(const unsigned char** out,
unsigned char* outlen,
const unsigned char* client_list,
- unsigned int client_list_len,
+ size_t client_list_len,
const unsigned char* server_list,
- unsigned int server_list_len) {
+ size_t server_list_len) {
const unsigned char* client_current = client_list;
while ((unsigned int)(client_current - client_list) < client_list_len) {
unsigned char client_current_len = *(client_current++);
@@ -1219,7 +1240,8 @@ static int server_handshaker_factory_npn_advertised_callback(
tsi_ssl_server_handshaker_factory* factory =
(tsi_ssl_server_handshaker_factory*)arg;
*out = factory->alpn_protocol_list;
- *outlen = factory->alpn_protocol_list_length;
+ GPR_ASSERT(factory->alpn_protocol_list_length <= UINT_MAX);
+ *outlen = (unsigned int)factory->alpn_protocol_list_length;
return SSL_TLSEXT_ERR_OK;
}
@@ -1277,8 +1299,10 @@ tsi_result tsi_create_ssl_client_handshaker_factory(
break;
}
#if TSI_OPENSSL_ALPN_SUPPORT
- if (SSL_CTX_set_alpn_protos(ssl_context, impl->alpn_protocol_list,
- impl->alpn_protocol_list_length)) {
+ GPR_ASSERT(impl->alpn_protocol_list_length < UINT_MAX);
+ if (SSL_CTX_set_alpn_protos(
+ ssl_context, impl->alpn_protocol_list,
+ (unsigned int)impl->alpn_protocol_list_length)) {
gpr_log(GPR_ERROR, "Could not set alpn protocol list to context.");
result = TSI_INVALID_ARGUMENT;
break;