Commit aebc3a03 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

more int to size_t conversions, fixing one or more amd64 bugs

plus a whitespace patch on config.c from vicman


svn:r2482
parent 92bb360a
......@@ -237,12 +237,12 @@ int read_to_buf_tls(tor_tls *tls, size_t at_most, buf_t *buf) {
* from the buffer. Return the number of bytes written on success,
* -1 on failure. Return 0 if write() would block.
*/
int flush_buf(int s, buf_t *buf, int *buf_flushlen)
int flush_buf(int s, buf_t *buf, size_t *buf_flushlen)
{
int write_result;
assert_buf_ok(buf);
tor_assert(buf_flushlen && (s>=0) && ((unsigned)*buf_flushlen <= buf->datalen));
tor_assert(buf_flushlen && (s>=0) && (*buf_flushlen <= buf->datalen));
if(*buf_flushlen == 0) /* nothing to flush */
return 0;
......@@ -266,7 +266,7 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen)
/** As flush_buf, but writes data to a TLS connection.
*/
int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen)
int flush_buf_tls(tor_tls *tls, buf_t *buf, size_t *buf_flushlen)
{
int r;
assert_buf_ok(buf);
......@@ -290,7 +290,7 @@ int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen)
*
* Return the new length of the buffer on success, -1 on failure.
*/
int write_to_buf(const char *string, int string_len, buf_t *buf) {
int write_to_buf(const char *string, size_t string_len, buf_t *buf) {
/* append string to buf (growing as needed, return -1 if "too big")
* return total number of bytes on the buf
......@@ -348,10 +348,10 @@ int fetch_from_buf(char *string, size_t string_len, buf_t *buf) {
* Else, change nothing and return 0.
*/
int fetch_from_buf_http(buf_t *buf,
char **headers_out, int max_headerlen,
char **body_out, int *body_used, int max_bodylen) {
char **headers_out, size_t max_headerlen,
char **body_out, size_t *body_used, size_t max_bodylen) {
char *headers, *body, *p;
int headerlen, bodylen, contentlen;
size_t headerlen, bodylen, contentlen;
assert_buf_ok(buf);
......@@ -382,11 +382,13 @@ int fetch_from_buf_http(buf_t *buf,
#define CONTENT_LENGTH "\r\nContent-Length: "
p = strstr(headers, CONTENT_LENGTH);
if (p) {
contentlen = atoi(p+strlen(CONTENT_LENGTH));
if (contentlen < 0) {
int i;
i = atoi(p+strlen(CONTENT_LENGTH));
if (i < 0) {
log_fn(LOG_WARN, "Content-Length is less than zero; it looks like someone is trying to crash us.");
return -1;
}
contentlen = i;
/* if content-length is malformed, then our body length is 0. fine. */
log_fn(LOG_DEBUG,"Got a contentlen of %d.",contentlen);
if(bodylen < contentlen) {
......
......@@ -350,7 +350,7 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
int r;
char payload[2+4+DIGEST_LEN+ONIONSKIN_CHALLENGE_LEN];
char *onionskin;
int payload_len;
size_t payload_len;
tor_assert(circ && CIRCUIT_IS_ORIGIN(circ));
......
This diff is collapsed.
......@@ -376,8 +376,10 @@ static int connection_create_listener(const char *bindaddress, uint16_t bindport
static int connection_handle_listener_read(connection_t *conn, int new_type) {
int news; /* the new socket */
connection_t *newconn;
struct sockaddr_in remote; /* information about the remote peer when connecting to other routers */
int remotelen = sizeof(struct sockaddr_in); /* length of the remote address */
/* information about the remote peer when connecting to other routers */
struct sockaddr_in remote;
/* length of the remote address. Must be an int, since accept() needs that. */
int remotelen = sizeof(struct sockaddr_in);
news = accept(conn->s,(struct sockaddr *)&remote,&remotelen);
if (news == -1) { /* accept() error */
......@@ -811,7 +813,7 @@ static int connection_read_to_buf(connection_t *conn) {
}
/** A pass-through to fetch_from_buf. */
int connection_fetch_from_buf(char *string, int len, connection_t *conn) {
int connection_fetch_from_buf(char *string, size_t len, connection_t *conn) {
return fetch_from_buf(string, len, conn->inbuf);
}
......@@ -953,7 +955,7 @@ int connection_handle_write(connection_t *conn) {
/** Append <b>len</b> bytes of <b>string</b> onto <b>conn</b>'s
* outbuf, and ask it to start writing.
*/
void connection_write_to_buf(const char *string, int len, connection_t *conn) {
void connection_write_to_buf(const char *string, size_t len, connection_t *conn) {
if(!len || conn->marked_for_close)
return;
......
......@@ -129,7 +129,7 @@ int
connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_layer)
{
char payload[5];
int payload_len=1;
size_t payload_len=1;
circuit_t *circ;
if(conn->has_sent_end) {
......@@ -625,11 +625,11 @@ int connection_ap_make_bridge(char *address, uint16_t port) {
void connection_ap_handshake_socks_resolved(connection_t *conn,
int answer_type,
int answer_len,
size_t answer_len,
const char *answer)
{
char buf[256];
int replylen;
size_t replylen;
if (answer_type == RESOLVED_TYPE_IPV4) {
uint32_t a = get_uint32(answer);
......@@ -686,7 +686,7 @@ void connection_ap_handshake_socks_resolved(connection_t *conn,
* Otherwise, send back a reply based on whether <b>success</b> is 1 or 0.
*/
void connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
int replylen, int success) {
size_t replylen, int success) {
char buf[256];
if(replylen) { /* we already have a reply in mind */
......
......@@ -28,21 +28,21 @@
static void
directory_initiate_command_router(routerinfo_t *router, uint8_t purpose,
const char *payload, int payload_len);
const char *payload, size_t payload_len);
static void
directory_initiate_command_trusted_dir(trusted_dir_server_t *dirserv,
uint8_t purpose, const char *payload, int payload_len);
uint8_t purpose, const char *payload, size_t payload_len);
static void
directory_initiate_command(const char *address, uint32_t addr, uint16_t port,
const char *platform,
const char *digest, uint8_t purpose,
const char *payload, int payload_len);
const char *payload, size_t payload_len);
static void
directory_send_command(connection_t *conn, const char *platform,
uint16_t dir_port, int purpose,
const char *payload, int payload_len);
const char *payload, size_t payload_len);
static int directory_handle_command(connection_t *conn);
/********* START VARIABLES **********/
......@@ -71,7 +71,7 @@ char rend_fetch_url[] = "/tor/rendezvous/";
*/
void
directory_post_to_dirservers(uint8_t purpose, const char *payload,
int payload_len)
size_t payload_len)
{
int i;
routerinfo_t *router;
......@@ -97,7 +97,7 @@ directory_post_to_dirservers(uint8_t purpose, const char *payload,
*/
void
directory_get_from_dirserver(uint8_t purpose, const char *payload,
int payload_len)
size_t payload_len)
{
routerinfo_t *r = NULL;
trusted_dir_server_t *ds = NULL;
......@@ -139,7 +139,7 @@ directory_get_from_dirserver(uint8_t purpose, const char *payload,
*/
static void
directory_initiate_command_router(routerinfo_t *router, uint8_t purpose,
const char *payload, int payload_len)
const char *payload, size_t payload_len)
{
directory_initiate_command(router->address, router->addr, router->dir_port,
router->platform, router->identity_digest,
......@@ -148,7 +148,7 @@ directory_initiate_command_router(routerinfo_t *router, uint8_t purpose,
static void
directory_initiate_command_trusted_dir(trusted_dir_server_t *dirserv,
uint8_t purpose, const char *payload, int payload_len)
uint8_t purpose, const char *payload, size_t payload_len)
{
directory_initiate_command(dirserv->address, dirserv->addr,dirserv->dir_port,
NULL, dirserv->digest, purpose, payload, payload_len);
......@@ -158,7 +158,7 @@ static void
directory_initiate_command(const char *address, uint32_t addr,
uint16_t dir_port, const char *platform,
const char *digest, uint8_t purpose,
const char *payload, int payload_len)
const char *payload, size_t payload_len)
{
connection_t *conn;
......@@ -257,7 +257,7 @@ directory_initiate_command(const char *address, uint32_t addr,
static void
directory_send_command(connection_t *conn, const char *platform,
uint16_t dir_port, int purpose,
const char *payload, int payload_len) {
const char *payload, size_t payload_len) {
char tmp[8192];
char proxystring[128];
char hoststring[128];
......@@ -466,7 +466,7 @@ connection_dir_client_reached_eof(connection_t *conn)
{
char *body;
char *headers;
int body_len=0;
size_t body_len=0;
int status_code;
time_t now, date_header=0;
int delta;
......@@ -512,7 +512,7 @@ connection_dir_client_reached_eof(connection_t *conn)
}
tor_free(body);
body = new_body;
body_len = (int)new_len;
body_len = new_len;
}
if(conn->purpose == DIR_PURPOSE_FETCH_DIR) {
......@@ -671,7 +671,7 @@ static char answer503[] = "HTTP/1.0 503 Directory unavailable\r\n\r\n";
* Always return 0. */
static int
directory_handle_command_get(connection_t *conn, char *headers,
char *body, int body_len)
char *body, size_t body_len)
{
size_t dlen;
const char *cp;
......@@ -738,7 +738,7 @@ directory_handle_command_get(connection_t *conn, char *headers,
if(!strcmpstart(url,"/tor/rendezvous/")) {
/* rendezvous descriptor fetch */
const char *descp;
int desc_len;
size_t desc_len;
if(!authdir_mode()) {
/* We don't hand out rend descs. In fact, it could be a security
......@@ -755,7 +755,7 @@ directory_handle_command_get(connection_t *conn, char *headers,
format_rfc1123_time(date, time(NULL));
snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: application/octet-stream\r\n\r\n",
date,
desc_len); /* can't include descp here, because it's got nuls */
(int)desc_len); /* can't include descp here, because it's got nuls */
connection_write_to_buf(tmp, strlen(tmp), conn);
connection_write_to_buf(descp, desc_len, conn);
break;
......@@ -783,7 +783,7 @@ directory_handle_command_get(connection_t *conn, char *headers,
* 400. Always return 0. */
static int
directory_handle_command_post(connection_t *conn, char *headers,
char *body, int body_len)
char *body, size_t body_len)
{
const char *cp;
char *url;
......@@ -848,7 +848,7 @@ directory_handle_command_post(connection_t *conn, char *headers,
*/
static int directory_handle_command(connection_t *conn) {
char *headers=NULL, *body=NULL;
int body_len=0;
size_t body_len=0;
int r;
tor_assert(conn && conn->type == CONN_TYPE_DIR);
......@@ -858,6 +858,7 @@ static int directory_handle_command(connection_t *conn) {
&body, &body_len, MAX_BODY_SIZE)) {
case -1: /* overflow */
log_fn(LOG_WARN,"input too large. Failing.");
/*XXX009 needs a better warn message */
return -1;
case 0:
log_fn(LOG_DEBUG,"command not all here yet.");
......
......@@ -468,7 +468,7 @@ list_running_servers(char **nicknames_out)
connection_t *conn;
char *cp;
int i;
int length;
size_t length;
smartlist_t *nicknames_up, *nicknames_down;
char *name;
const char *s;
......@@ -554,7 +554,7 @@ dirserv_remove_old_servers(int age)
* failure.
*/
int
dirserv_dump_directory_to_string(char *s, unsigned int maxlen,
dirserv_dump_directory_to_string(char *s, size_t maxlen,
crypto_pk_env_t *private_key)
{
char *cp, *eos;
......
......@@ -145,7 +145,7 @@ static void purge_expired_resolves(uint32_t now) {
static void send_resolved_cell(connection_t *conn, uint8_t answer_type)
{
char buf[RELAY_PAYLOAD_SIZE];
int buflen;
size_t buflen;
buf[0] = answer_type;
......
......@@ -55,7 +55,6 @@ int onion_pending_add(circuit_t *circ) {
ol_tail->next = tmp;
ol_tail = tmp;
return 0;
}
/** Remove the first item from ol_list and return it, or return
......@@ -192,7 +191,7 @@ onion_skin_server_handshake(char *onion_skin, /* ONIONSKIN_CHALLENGE_LEN bytes *
crypto_pk_env_t *prev_private_key,
char *handshake_reply_out, /* ONIONSKIN_REPLY_LEN bytes */
char *key_out,
int key_out_len)
size_t key_out_len)
{
char challenge[ONIONSKIN_CHALLENGE_LEN];
crypto_dh_env_t *dh = NULL;
......@@ -277,7 +276,7 @@ int
onion_skin_client_handshake(crypto_dh_env_t *handshake_state,
char *handshake_reply, /* Must be ONIONSKIN_REPLY_LEN bytes */
char *key_out,
int key_out_len)
size_t key_out_len)
{
int len;
char *key_material=NULL;
......
......@@ -913,7 +913,7 @@ typedef struct {
struct socks_request_t {
char socks_version; /**< Which version of SOCKS did the client use? */
int command; /**< What has the user requested? One of CONNECT or RESOLVE. */
int replylen; /**< Length of <b>reply</b>. */
size_t replylen; /**< Length of <b>reply</b>. */
char reply[MAX_SOCKS_REPLY_LEN]; /**< Write an entry into this string if
* we want to specify our own socks reply,
* rather than using the default socks4 or
......@@ -941,14 +941,14 @@ const char *_buf_peek_raw_buffer(const buf_t *buf);
int read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof);
int read_to_buf_tls(tor_tls *tls, size_t at_most, buf_t *buf);
int flush_buf(int s, buf_t *buf, int *buf_flushlen);
int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen);
int flush_buf(int s, buf_t *buf, size_t *buf_flushlen);
int flush_buf_tls(tor_tls *tls, buf_t *buf, size_t *buf_flushlen);
int write_to_buf(const char *string, int string_len, buf_t *buf);
int write_to_buf(const char *string, size_t string_len, buf_t *buf);
int fetch_from_buf(char *string, size_t string_len, buf_t *buf);
int fetch_from_buf_http(buf_t *buf,
char **headers_out, int max_headerlen,
char **body_out, int *body_used, int max_bodylen);
char **headers_out, size_t max_headerlen,
char **body_out, size_t *body_used, size_t max_bodylen);
int fetch_from_buf_socks(buf_t *buf, socks_request_t *req);
void assert_buf_ok(buf_t *buf);
......@@ -1083,12 +1083,12 @@ void connection_bucket_refill(struct timeval *now);
int connection_handle_read(connection_t *conn);
int connection_fetch_from_buf(char *string, int len, connection_t *conn);
int connection_fetch_from_buf(char *string, size_t len, connection_t *conn);
int connection_wants_to_flush(connection_t *conn);
int connection_outbuf_too_full(connection_t *conn);
int connection_handle_write(connection_t *conn);
void connection_write_to_buf(const char *string, int len, connection_t *conn);
void connection_write_to_buf(const char *string, size_t len, connection_t *conn);
connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port);
connection_t *connection_get_by_identity_digest(const char *digest, int type);
......@@ -1125,10 +1125,10 @@ int connection_ap_handshake_send_resolve(connection_t *ap_conn, circuit_t *circ)
int connection_ap_make_bridge(char *address, uint16_t port);
void connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
int replylen, int success);
size_t replylen, int success);
void connection_ap_handshake_socks_resolved(connection_t *conn,
int answer_type,
int answer_len,
size_t answer_len,
const char *answer);
int connection_exit_begin_conn(cell_t *cell, circuit_t *circ);
......@@ -1175,9 +1175,9 @@ int assign_to_cpuworker(connection_t *cpuworker, unsigned char question_type,
/********************************* directory.c ***************************/
void directory_post_to_dirservers(uint8_t purpose, const char *payload,
int payload_len);
size_t payload_len);
void directory_get_from_dirserver(uint8_t purpose, const char *payload,
int payload_len);
size_t payload_len);
int connection_dir_process_inbuf(connection_t *conn);
int connection_dir_finished_flushing(connection_t *conn);
int connection_dir_finished_connecting(connection_t *conn);
......@@ -1254,12 +1254,12 @@ int onion_skin_server_handshake(char *onion_skin,
crypto_pk_env_t *prev_private_key,
char *handshake_reply_out,
char *key_out,
int key_out_len);
size_t key_out_len);
int onion_skin_client_handshake(crypto_dh_env_t *handshake_state,
char *handshake_reply,
char *key_out,
int key_out_len);
size_t key_out_len);
/********************************* relay.c ***************************/
......@@ -1273,7 +1273,7 @@ void relay_header_pack(char *dest, const relay_header_t *src);
void relay_header_unpack(relay_header_t *dest, const char *src);
int connection_edge_send_command(connection_t *fromconn, circuit_t *circ,
int relay_command, const char *payload,
int payload_len, crypt_path_t *cpath_layer);
size_t payload_len, crypt_path_t *cpath_layer);
int connection_edge_package_raw_inbuf(connection_t *conn);
void connection_edge_consider_sending_sendme(connection_t *conn);
......@@ -1302,11 +1302,11 @@ char *rep_hist_get_bandwidth_lines(void);
void rend_client_introcirc_has_opened(circuit_t *circ);
void rend_client_rendcirc_has_opened(circuit_t *circ);
int rend_client_introduction_acked(circuit_t *circ, const char *request, int request_len);
int rend_client_introduction_acked(circuit_t *circ, const char *request, size_t request_len);
void rend_client_refetch_renddesc(const char *query);
int rend_client_remove_intro_point(char *failed_intro, const char *query);
int rend_client_rendezvous_acked(circuit_t *circ, const char *request, int request_len);
int rend_client_receive_rendezvous(circuit_t *circ, const char *request, int request_len);
int rend_client_rendezvous_acked(circuit_t *circ, const char *request, size_t request_len);
int rend_client_receive_rendezvous(circuit_t *circ, const char *request, size_t request_len);
void rend_client_desc_fetched(char *query, int success);
char *rend_client_get_random_intro(char *query);
......@@ -1325,19 +1325,19 @@ typedef struct rend_service_descriptor_t {
int rend_cmp_service_ids(const char *one, const char *two);
void rend_process_relay_cell(circuit_t *circ, int command, int length,
void rend_process_relay_cell(circuit_t *circ, int command, size_t length,
const char *payload);
void rend_service_descriptor_free(rend_service_descriptor_t *desc);
int rend_encode_service_descriptor(rend_service_descriptor_t *desc,
crypto_pk_env_t *key,
char **str_out,
int *len_out);
rend_service_descriptor_t *rend_parse_service_descriptor(const char *str, int len);
size_t *len_out);
rend_service_descriptor_t *rend_parse_service_descriptor(const char *str, size_t len);
int rend_get_service_id(crypto_pk_env_t *pk, char *out);
typedef struct rend_cache_entry_t {
int len; /* Length of desc */
size_t len; /* Length of desc */
time_t received; /* When did we get the descriptor? */
char *desc; /* Service descriptor */
rend_service_descriptor_t *parsed; /* Parsed value of 'desc' */
......@@ -1346,9 +1346,9 @@ typedef struct rend_cache_entry_t {
void rend_cache_init(void);
void rend_cache_clean(void);
int rend_valid_service_id(const char *query);
int rend_cache_lookup_desc(const char *query, const char **desc, int *desc_len);
int rend_cache_lookup_desc(const char *query, const char **desc, size_t *desc_len);
int rend_cache_lookup_entry(const char *query, rend_cache_entry_t **entry_out);
int rend_cache_store(const char *desc, int desc_len);
int rend_cache_store(const char *desc, size_t desc_len);
/********************************* rendservice.c ***************************/
......@@ -1359,18 +1359,18 @@ void rend_services_introduce(void);
void rend_services_upload(int force);
void rend_service_intro_has_opened(circuit_t *circuit);
int rend_service_intro_established(circuit_t *circuit, const char *request, int request_len);
int rend_service_intro_established(circuit_t *circuit, const char *request, size_t request_len);
void rend_service_rendezvous_has_opened(circuit_t *circuit);
int rend_service_introduce(circuit_t *circuit, const char *request, int request_len);
int rend_service_introduce(circuit_t *circuit, const char *request, size_t request_len);
void rend_service_relaunch_rendezvous(circuit_t *oldcirc);
int rend_service_set_connection_addr_port(connection_t *conn, circuit_t *circ);
void rend_service_dump_stats(int severity);
/********************************* rendmid.c *******************************/
int rend_mid_establish_intro(circuit_t *circ, const char *request, int request_len);
int rend_mid_introduce(circuit_t *circ, const char *request, int request_len);
int rend_mid_establish_rendezvous(circuit_t *circ, const char *request, int request_len);
int rend_mid_rendezvous(circuit_t *circ, const char *request, int request_len);
int rend_mid_establish_intro(circuit_t *circ, const char *request, size_t request_len);
int rend_mid_introduce(circuit_t *circ, const char *request, size_t request_len);
int rend_mid_establish_rendezvous(circuit_t *circ, const char *request, size_t request_len);
int rend_mid_rendezvous(circuit_t *circ, const char *request, size_t request_len);
/********************************* router.c ***************************/
......@@ -1395,7 +1395,7 @@ routerinfo_t *router_get_my_routerinfo(void);
const char *router_get_my_descriptor(void);
int router_is_me(routerinfo_t *router);
int router_rebuild_descriptor(void);
int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
crypto_pk_env_t *ident_key);
int is_legal_nickname(const char *s);
int is_legal_nickname_or_hexdigest(const char *s);
......
......@@ -404,7 +404,7 @@ void relay_header_unpack(relay_header_t *dest, const char *src) {
*/
int connection_edge_send_command(connection_t *fromconn, circuit_t *circ,
int relay_command, const char *payload,
int payload_len, crypt_path_t *cpath_layer) {
size_t payload_len, crypt_path_t *cpath_layer) {
cell_t cell;
relay_header_t rh;
int cell_direction;
......@@ -853,7 +853,7 @@ uint64_t stats_n_data_bytes_received = 0;
* Return -1 if conn should be marked for close, else return 0.
*/
int connection_edge_package_raw_inbuf(connection_t *conn) {
int amount_to_process, length;
size_t amount_to_process, length;
char payload[CELL_PAYLOAD_SIZE];
circuit_t *circ;
......
......@@ -52,7 +52,8 @@ rend_client_send_establish_rendezvous(circuit_t *circ)
*/
int
rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc) {
int payload_len, r;
size_t payload_len;
int r;
char payload[RELAY_PAYLOAD_SIZE];
char tmp[(MAX_NICKNAME_LEN+1)+REND_COOKIE_LEN+DH_KEY_LEN];
rend_cache_entry_t *entry;
......@@ -152,7 +153,7 @@ rend_client_rendcirc_has_opened(circuit_t *circ)
*/
int
rend_client_introduction_acked(circuit_t *circ,
const char *request, int request_len)
const char *request, size_t request_len)
{
char *nickname;
circuit_t *rendcirc;
......@@ -280,7 +281,7 @@ rend_client_remove_intro_point(char *failed_intro, const char *query)
* the circuit to C_REND_READY.
*/
int
rend_client_rendezvous_acked(circuit_t *circ, const char *request, int request_len)
rend_client_rendezvous_acked(circuit_t *circ, const char *request, size_t request_len)
{
/* we just got an ack for our establish-rendezvous. switch purposes. */
if(circ->purpose != CIRCUIT_PURPOSE_C_ESTABLISH_REND) {
......@@ -295,7 +296,7 @@ rend_client_rendezvous_acked(circuit_t *circ, const char *request, int request_l
/** Bob sent us a rendezvous cell; join the circuits. */
int
rend_client_receive_rendezvous(circuit_t *circ, const char *request, int request_len)
rend_client_receive_rendezvous(circuit_t *circ, const char *request, size_t request_len)
{
crypt_path_t *hop;
char keys[DIGEST_LEN+CPATH_KEY_MATERIAL_LEN];
......
......@@ -39,17 +39,19 @@ void rend_service_descriptor_free(rend_service_descriptor_t *desc)
int
rend_encode_service_descriptor(rend_service_descriptor_t *desc,
crypto_pk_env_t *key,
char **str_out, int *len_out)
char **str_out, size_t *len_out)
{
char *buf, *cp, *ipoint;
int i, keylen, asn1len;
int i;
size_t keylen, asn1len;
keylen = crypto_pk_keysize(desc->pk);
buf = tor_malloc(keylen*2); /* Too long, but that's okay. */
asn1len = crypto_pk_asn1_encode(desc->pk, buf, keylen*2);
if (asn1len<0) {
i = crypto_pk_asn1_encode(desc->pk, buf, keylen*2);
if (i<0) {
tor_free(buf);
return -1;
}
asn1len = i;
*len_out = 2 + asn1len + 4 + 2 + keylen;
for (i = 0; i < desc->n_intro_points; ++i) {
*len_out += strlen(desc->intro_points[i]) + 1;
......@@ -75,7 +77,7 @@ rend_encode_service_descriptor(rend_service_descriptor_t *desc,
return -1;
}
cp += i;
tor_assert(*len_out == (cp-*str_out));
tor_assert(*len_out == (size_t)(cp-*str_out));
return 0;
}
......@@ -84,10 +86,11 @@ rend_encode_service_descriptor(rend_service_descriptor_t *desc,
* return NULL.
*/
rend_service_descriptor_t *rend_parse_service_descriptor(
const char *str, int len)
const char *str, size_t len)
{
rend_service_descriptor_t *result = NULL;
int keylen, asn1len, i;
int i;
size_t keylen, asn1len;
const char *end, *cp, *eos;
result = tor_malloc_zero(sizeof(rend_service_descriptor_t));
......@@ -96,7 +99,7 @@ rend_service_descriptor_t *rend_parse_service_descriptor(
if (end-cp < 2) goto truncated;
asn1len = ntohs(get_uint16(cp));
cp += 2;
if (end-cp < asn1len) goto truncated;
if ((size_t)(end-cp) < asn1len) goto truncated;
result->pk = crypto_pk_asn1_decode(cp, asn1len);
if (!result->pk) goto truncated;
cp += asn1len;
......@@ -115,8 +118,9 @@ rend_service_descriptor_t *rend_parse_service_descriptor(