diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-11-14 01:07:52 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-11-14 01:07:52 +0000 |
commit | 9243e5417704656dbfee91d2b6e06ae19f70aa24 (patch) | |
tree | 4a1957e97e4c4d36e0af0e74da1a5162fd60b1dc | |
parent | 0f6402f17b9d4017aec608b10cb031512c543bc5 (diff) | |
download | tor-9243e5417704656dbfee91d2b6e06ae19f70aa24.tar.gz tor-9243e5417704656dbfee91d2b6e06ae19f70aa24.zip |
r9313@totoro: nickm | 2006-11-13 20:07:41 -0500
Try to compile with fewer warnings on irix64's MIPSpro compiler /
environment, which apparently believes that:
- off_t can be bigger than size_t.
- only mean kids assign things they do not subsequently inspect.
I don't try to fix the "error" that makes it say:
cc-3970 cc: WARNING File = main.c, Line = 1277
conversion from pointer to same-sized integral type (potential portability
problem)
uintptr_t sig = (uintptr_t)arg;
Because really, what can you do about a compiler that claims to be c99
but doesn't understand that void* x = NULL; uintptr_t y = (uintptr_t) x;
is safe?
svn:r8948
-rw-r--r-- | src/common/compat.c | 2 | ||||
-rw-r--r-- | src/common/torgzip.c | 14 | ||||
-rw-r--r-- | src/common/torint.h | 10 | ||||
-rw-r--r-- | src/common/util.c | 7 | ||||
-rw-r--r-- | src/or/config.c | 2 | ||||
-rw-r--r-- | src/or/control.c | 8 | ||||
-rw-r--r-- | src/or/dirserv.c | 5 | ||||
-rw-r--r-- | src/or/eventdns.c | 11 | ||||
-rw-r--r-- | src/or/rendclient.c | 2 | ||||
-rw-r--r-- | src/or/routerparse.c | 2 |
10 files changed, 48 insertions, 15 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index db38e757e3..75e37a8b79 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -135,7 +135,7 @@ tor_mmap_file(const char *filename) return NULL; } - size = filesize = lseek(fd, 0, SEEK_END); + size = filesize = (size_t) lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); /* ensure page alignment */ page_size = getpagesize(); diff --git a/src/common/torgzip.c b/src/common/torgzip.c index 83438462a2..badd45be87 100644 --- a/src/common/torgzip.c +++ b/src/common/torgzip.c @@ -121,7 +121,12 @@ tor_gzip_compress(char **out, size_t *out_len, out_size *= 2; *out = tor_realloc(*out, out_size); stream->next_out = (unsigned char*)(*out + offset); - stream->avail_out = out_size - offset; + if (out_size - offset > UINT_MAX) { + log_warn(LD_BUG, "Ran over unsigned int limit of zlib while " + "uncompressing."); + goto err; + } + stream->avail_out = (unsigned int)(out_size - offset); break; default: log_warn(LD_GENERAL, "Gzip compression didn't finish: %s", @@ -238,7 +243,12 @@ tor_gzip_uncompress(char **out, size_t *out_len, out_size *= 2; *out = tor_realloc(*out, out_size); stream->next_out = (unsigned char*)(*out + offset); - stream->avail_out = out_size - offset; + if (out_size - offset > UINT_MAX) { + log_warn(LD_BUG, "Ran over unsigned int limit of zlib while " + "uncompressing."); + goto err; + } + stream->avail_out = (unsigned int)(out_size - offset); break; default: log_warn(LD_GENERAL, "Gzip decompression returned an error: %s", diff --git a/src/common/torint.h b/src/common/torint.h index f520072aa2..536823c6b3 100644 --- a/src/common/torint.h +++ b/src/common/torint.h @@ -287,6 +287,16 @@ typedef uint32_t uintptr_t; #endif /* time_t_is_signed */ #endif /* ifndef(TIME_MAX) */ +#ifndef SIZE_T_MAX +#if (SIZEOF_SIZE_T == 4) +#define SIZE_T_MAX 0xfffffffful +#elif (SIZEOF_SIZE_T == 8) +#define SIZE_T_MAX 0xfffffffffffffffful +#else +#error "Can't define SIZE_T_MAX" +#endif +#endif + /* Any size_t larger than this amount is likely to be an underflow. */ #define SIZE_T_CEILING (sizeof(char)<<(sizeof(size_t)*8 - 1)) diff --git a/src/common/util.c b/src/common/util.c index d5a71d2743..15e08fa898 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1324,9 +1324,12 @@ read_file_to_str(const char *filename, int bin, size_t *size_out) return NULL; } - string = tor_malloc(statbuf.st_size+1); + if (statbuf.st_size+1 > SIZE_T_MAX) + return NULL; + + string = tor_malloc((size_t)(statbuf.st_size+1)); - r = read_all(fd,string,statbuf.st_size,0); + r = read_all(fd,string,(size_t)statbuf.st_size,0); if (r<0) { log_warn(LD_FS,"Error reading from file \"%s\": %s", filename, strerror(errno)); diff --git a/src/or/config.c b/src/or/config.c index 36e829bc71..1db8d65f4f 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -3688,7 +3688,7 @@ static const struct { { "1.1a", LE_11A }, { "1.1b", LE_11B }, { "1.2", LE_12 }, - { NULL, 0 } + { NULL, LE_OTHER } }; static le_version_t diff --git a/src/or/control.c b/src/or/control.c index 18d0e47d2b..9470e49e0d 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -1152,7 +1152,7 @@ handle_control_authenticate(control_connection_t *conn, uint32_t len, used_quoted_string = 1; } } - if (options->CookieAuthentication) { + if (options->CookieAuthentication && authentication_cookie_is_set) { if (password_len != AUTHENTICATION_COOKIE_LEN) { log_warn(LD_CONTROL, "Got authentication cookie with wrong length (%d)", (int)password_len); @@ -1685,12 +1685,16 @@ handle_getinfo_helper(control_connection_t *control_conn, } else if (!strcmpstart(question, "dir/server/")) { size_t answer_len = 0, url_len = strlen(question)+2; char *url = tor_malloc(url_len); - int res; smartlist_t *descs = smartlist_create(); const char *msg; + int res; char *cp; tor_snprintf(url, url_len, "/tor/%s", question+4); res = dirserv_get_routerdescs(descs, url, &msg); + if (res) { + log_warn(LD_CONTROL, "getinfo '%s': %s", question, msg); + return -1; + } SMARTLIST_FOREACH(descs, signed_descriptor_t *, sd, answer_len += sd->signed_descriptor_len); cp = *answer = tor_malloc(answer_len+1); diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 3a457345b9..a9cd0c4eab 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -1953,7 +1953,8 @@ connection_dirserv_add_servers_to_outbuf(dir_connection_t *conn) static int connection_dirserv_add_dir_bytes_to_outbuf(dir_connection_t *conn) { - int bytes, remaining; + ssize_t bytes; + int64_t remaining; bytes = DIRSERV_BUFFER_MIN - buf_datalen(conn->_base.outbuf); tor_assert(bytes > 0); @@ -1962,7 +1963,7 @@ connection_dirserv_add_dir_bytes_to_outbuf(dir_connection_t *conn) bytes = 8192; remaining = conn->cached_dir->dir_z_len - conn->cached_dir_offset; if (bytes > remaining) - bytes = remaining; + bytes = (ssize_t) remaining; if (conn->zlib_state) { connection_write_to_buf_zlib(conn, diff --git a/src/or/eventdns.c b/src/or/eventdns.c index 39640cf885..740801ad30 100644 --- a/src/or/eventdns.c +++ b/src/or/eventdns.c @@ -887,6 +887,8 @@ reply_parse(u8 *packet, int length) { GET16(answers); GET16(authority); GET16(additional); + (void) authority; + (void) additional; req = request_find_from_trans_id(trans_id); if (!req) return -1; @@ -1224,7 +1226,7 @@ evdns_request_data_build(const char *const name, const int name_len, const u16 t APPEND16(class); #undef APPEND16 - return j; + return (int)j; } // this is a libevent callback function which is called when a request @@ -1792,6 +1794,7 @@ search_make_new(const struct search_state *const state, int n, const char *const // we ran off the end of the list and still didn't find the requested string abort(); + return NULL; /* unreachable. */ } static int @@ -2005,10 +2008,12 @@ evdns_resolv_conf_parse(int flags, const char *const filename) { } if (st.st_size > 65535) { err = 3; goto out1; } // no resolv.conf should be any bigger - resolv = (u8 *) malloc(st.st_size + 1); + resolv = (u8 *) malloc((size_t)st.st_size + 1); if (!resolv) { err = 4; goto out1; } - if (read(fd, resolv, st.st_size) != st.st_size) { err = 5; goto out2; } + if (read(fd, resolv, (size_t)st.st_size) != st.st_size) { + err = 5; goto out2; + } resolv[st.st_size] = 0; // we malloced an extra byte start = (char *) resolv; diff --git a/src/or/rendclient.c b/src/or/rendclient.c index 4d0cdd9fc3..32c7d2946a 100644 --- a/src/or/rendclient.c +++ b/src/or/rendclient.c @@ -134,7 +134,7 @@ rend_client_send_introduction(origin_circuit_t *introcirc, * to avoid buffer overflows? */ r = crypto_pk_public_hybrid_encrypt(entry->parsed->pk, payload+DIGEST_LEN, tmp, - dh_offset+DH_KEY_LEN, + (int)(dh_offset+DH_KEY_LEN), PK_PKCS1_OAEP_PADDING, 0); if (r<0) { log_warn(LD_BUG,"Internal error: hybrid pk encrypt failed."); diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 671788cae3..a592c3d0f9 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -147,7 +147,7 @@ static struct { { "client-versions", K_CLIENT_VERSIONS, ARGS, NO_OBJ, NETSTATUS }, { "server-versions", K_SERVER_VERSIONS, ARGS, NO_OBJ, NETSTATUS }, { "eventdns", K_EVENTDNS, ARGS, NO_OBJ, RTR }, - { NULL, -1, NO_ARGS, NO_OBJ, ANY } + { NULL, _NIL, NO_ARGS, NO_OBJ, ANY } }; /* static function prototypes */ |