Merge commit '13298d90a90dc62d21d38f910171c9b57a8f0273'

This commit is contained in:
Nick Mathewson 2014-10-31 08:52:07 -04:00
commit 6f87aa3371
10 changed files with 47 additions and 25 deletions

View File

@ -0,0 +1,10 @@
o Minor bugfixes:
- Silence clang warnings under --enable-expensive-hardening, including:
+ implicit truncation of 64 bit values to 32 bit;
+ const char assignment to self;
+ tautological compare; and
+ additional parentheses around equality tests. (gcc uses these to
silence assignment, so clang warns when they're present in an
equality test. But we need to use extra parentheses in macros to
isolate them from other code).
Fixes bug 13577.

View File

@ -138,9 +138,10 @@ int
tor_open_cloexec(const char *path, int flags, unsigned mode) tor_open_cloexec(const char *path, int flags, unsigned mode)
{ {
int fd; int fd;
const char *p = path;
#ifdef O_CLOEXEC #ifdef O_CLOEXEC
path = sandbox_intern_string(path); p = sandbox_intern_string(path);
fd = open(path, flags|O_CLOEXEC, mode); fd = open(p, flags|O_CLOEXEC, mode);
if (fd >= 0) if (fd >= 0)
return fd; return fd;
/* If we got an error, see if it is EINVAL. EINVAL might indicate that, /* If we got an error, see if it is EINVAL. EINVAL might indicate that,
@ -150,8 +151,8 @@ tor_open_cloexec(const char *path, int flags, unsigned mode)
return -1; return -1;
#endif #endif
log_debug(LD_FS, "Opening %s with flags %x", path, flags); log_debug(LD_FS, "Opening %s with flags %x", p, flags);
fd = open(path, flags, mode); fd = open(p, flags, mode);
#ifdef FD_CLOEXEC #ifdef FD_CLOEXEC
if (fd >= 0) { if (fd >= 0) {
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {

View File

@ -562,17 +562,18 @@ const char *tor_socket_strerror(int e);
#else #else
#define SOCK_ERRNO(e) e #define SOCK_ERRNO(e) e
#if EAGAIN == EWOULDBLOCK #if EAGAIN == EWOULDBLOCK
#define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN) /* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */
#define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || 0)
#else #else
#define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || (e) == EWOULDBLOCK) #define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || (e) == EWOULDBLOCK)
#endif #endif
#define ERRNO_IS_EINPROGRESS(e) ((e) == EINPROGRESS) #define ERRNO_IS_EINPROGRESS(e) ((e) == EINPROGRESS || 0)
#define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == EINPROGRESS) #define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == EINPROGRESS || 0)
#define ERRNO_IS_ACCEPT_EAGAIN(e) \ #define ERRNO_IS_ACCEPT_EAGAIN(e) \
(ERRNO_IS_EAGAIN(e) || (e) == ECONNABORTED) (ERRNO_IS_EAGAIN(e) || (e) == ECONNABORTED)
#define ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e) \ #define ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e) \
((e) == EMFILE || (e) == ENFILE || (e) == ENOBUFS || (e) == ENOMEM) ((e) == EMFILE || (e) == ENFILE || (e) == ENOBUFS || (e) == ENOMEM)
#define ERRNO_IS_EADDRINUSE(e) ((e) == EADDRINUSE) #define ERRNO_IS_EADDRINUSE(e) (((e) == EADDRINUSE) || 0)
#define tor_socket_errno(sock) (errno) #define tor_socket_errno(sock) (errno)
#define tor_socket_strerror(e) strerror(e) #define tor_socket_strerror(e) strerror(e)
#endif #endif

View File

@ -62,7 +62,7 @@ crypto_pwbox(uint8_t **out, size_t *outlen_out,
pwbox_encoded_setlen_data(enc, encrypted_len); pwbox_encoded_setlen_data(enc, encrypted_len);
encrypted_portion = pwbox_encoded_getarray_data(enc); encrypted_portion = pwbox_encoded_getarray_data(enc);
set_uint32(encrypted_portion, htonl(input_len)); set_uint32(encrypted_portion, htonl((uint32_t)input_len));
memcpy(encrypted_portion+4, input, input_len); memcpy(encrypted_portion+4, input, input_len);
/* Now that all the data is in position, derive some keys, encrypt, and /* Now that all the data is in position, derive some keys, encrypt, and

View File

@ -38,8 +38,9 @@
} }
#endif #endif
/* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */
#define HT_EMPTY(head) \ #define HT_EMPTY(head) \
((head)->hth_n_entries == 0) (((head)->hth_n_entries == 0) || 0)
/* How many elements in 'head'? */ /* How many elements in 'head'? */
#define HT_SIZE(head) \ #define HT_SIZE(head) \

View File

@ -109,7 +109,8 @@ struct { \
*/ */
#define TOR_SLIST_FIRST(head) ((head)->slh_first) #define TOR_SLIST_FIRST(head) ((head)->slh_first)
#define TOR_SLIST_END(head) NULL #define TOR_SLIST_END(head) NULL
#define TOR_SLIST_EMPTY(head) (SLIST_FIRST(head) == TOR_SLIST_END(head)) /* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */
#define TOR_SLIST_EMPTY(head) ((SLIST_FIRST(head) == TOR_SLIST_END(head)) || 0)
#define TOR_SLIST_NEXT(elm, field) ((elm)->field.sle_next) #define TOR_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
#define TOR_SLIST_FOREACH(var, head, field) \ #define TOR_SLIST_FOREACH(var, head, field) \
@ -181,9 +182,11 @@ struct { \
/* /*
* List access methods * List access methods
*/ */
#define TOR_LIST_FIRST(head) ((head)->lh_first) #define TOR_LIST_FIRST(head) ((head)->lh_first)
#define TOR_LIST_END(head) NULL #define TOR_LIST_END(head) NULL
#define TOR_LIST_EMPTY(head) (TOR_LIST_FIRST(head) == TOR_LIST_END(head)) /* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */
#define TOR_LIST_EMPTY(head) \
((TOR_LIST_FIRST(head) == TOR_LIST_END(head)) || 0)
#define TOR_LIST_NEXT(elm, field) ((elm)->field.le_next) #define TOR_LIST_NEXT(elm, field) ((elm)->field.le_next)
#define TOR_LIST_FOREACH(var, head, field) \ #define TOR_LIST_FOREACH(var, head, field) \
@ -265,8 +268,10 @@ struct { \
* Simple queue access methods. * Simple queue access methods.
*/ */
#define TOR_SIMPLEQ_FIRST(head) ((head)->sqh_first) #define TOR_SIMPLEQ_FIRST(head) ((head)->sqh_first)
#define TOR_SIMPLEQ_END(head) NULL #define TOR_SIMPLEQ_END(head) NULL
#define TOR_SIMPLEQ_EMPTY(head) (TOR_SIMPLEQ_FIRST(head) == TOR_SIMPLEQ_END(head)) /* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */
#define TOR_SIMPLEQ_EMPTY(head) \
((TOR_SIMPLEQ_FIRST(head) == TOR_SIMPLEQ_END(head)) || 0)
#define TOR_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) #define TOR_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
#define TOR_SIMPLEQ_FOREACH(var, head, field) \ #define TOR_SIMPLEQ_FOREACH(var, head, field) \
@ -345,8 +350,9 @@ struct { \
/* XXX */ /* XXX */
#define TOR_TAILQ_PREV(elm, headname, field) \ #define TOR_TAILQ_PREV(elm, headname, field) \
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
/* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */
#define TOR_TAILQ_EMPTY(head) \ #define TOR_TAILQ_EMPTY(head) \
(TOR_TAILQ_FIRST(head) == TOR_TAILQ_END(head)) ((TOR_TAILQ_FIRST(head) == TOR_TAILQ_END(head)) || 0)
#define TOR_TAILQ_FOREACH(var, head, field) \ #define TOR_TAILQ_FOREACH(var, head, field) \
for((var) = TOR_TAILQ_FIRST(head); \ for((var) = TOR_TAILQ_FIRST(head); \
@ -462,8 +468,9 @@ struct { \
#define TOR_CIRCLEQ_END(head) ((void *)(head)) #define TOR_CIRCLEQ_END(head) ((void *)(head))
#define TOR_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next) #define TOR_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
#define TOR_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev) #define TOR_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
/* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */
#define TOR_CIRCLEQ_EMPTY(head) \ #define TOR_CIRCLEQ_EMPTY(head) \
(TOR_CIRCLEQ_FIRST(head) == TOR_CIRCLEQ_END(head)) ((TOR_CIRCLEQ_FIRST(head) == TOR_CIRCLEQ_END(head)) || 0)
#define TOR_CIRCLEQ_FOREACH(var, head, field) \ #define TOR_CIRCLEQ_FOREACH(var, head, field) \
for((var) = TOR_CIRCLEQ_FIRST(head); \ for((var) = TOR_CIRCLEQ_FIRST(head); \

View File

@ -847,8 +847,8 @@ channel_tls_handle_state_change_on_orconn(channel_tls_t *chan,
tor_assert(conn); tor_assert(conn);
tor_assert(conn->chan == chan); tor_assert(conn->chan == chan);
tor_assert(chan->conn == conn); tor_assert(chan->conn == conn);
/* -Werror appeasement */ /* Shut the compiler up without triggering -Wtautological-compare */
tor_assert(old_state == old_state); (void)old_state;
base_chan = TLS_CHAN_TO_BASE(chan); base_chan = TLS_CHAN_TO_BASE(chan);

View File

@ -273,8 +273,8 @@ ewma_alloc_circ_data(circuitmux_t *cmux,
tor_assert(circ); tor_assert(circ);
tor_assert(direction == CELL_DIRECTION_OUT || tor_assert(direction == CELL_DIRECTION_OUT ||
direction == CELL_DIRECTION_IN); direction == CELL_DIRECTION_IN);
/* Shut the compiler up */ /* Shut the compiler up without triggering -Wtautological-compare */
tor_assert(cell_count == cell_count); (void)cell_count;
cdata = tor_malloc_zero(sizeof(*cdata)); cdata = tor_malloc_zero(sizeof(*cdata));
cdata->base_.magic = EWMA_POL_CIRC_DATA_MAGIC; cdata->base_.magic = EWMA_POL_CIRC_DATA_MAGIC;

View File

@ -189,7 +189,8 @@ dir_connection_t *connection_dir_get_by_purpose_and_resource(
int any_other_active_or_conns(const or_connection_t *this_conn); int any_other_active_or_conns(const or_connection_t *this_conn);
#define connection_speaks_cells(conn) ((conn)->type == CONN_TYPE_OR) /* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */
#define connection_speaks_cells(conn) (((conn)->type == CONN_TYPE_OR) || 0)
int connection_is_listener(connection_t *conn); int connection_is_listener(connection_t *conn);
int connection_state_is_open(connection_t *conn); int connection_state_is_open(connection_t *conn);
int connection_state_is_connecting(connection_t *conn); int connection_state_is_connecting(connection_t *conn);

View File

@ -241,7 +241,7 @@ typedef enum {
#define PROXY_CONNECT 1 #define PROXY_CONNECT 1
#define PROXY_SOCKS4 2 #define PROXY_SOCKS4 2
#define PROXY_SOCKS5 3 #define PROXY_SOCKS5 3
/* !!!! If there is ever a PROXY_* type over 2, we must grow the proxy_type /* !!!! If there is ever a PROXY_* type over 3, we must grow the proxy_type
* field in or_connection_t */ * field in or_connection_t */
/* Pluggable transport proxy type. Don't use this in or_connection_t, /* Pluggable transport proxy type. Don't use this in or_connection_t,
@ -4317,7 +4317,8 @@ static INLINE void or_state_mark_dirty(or_state_t *state, time_t when)
/** Please turn this IP address into an FQDN, privately. */ /** Please turn this IP address into an FQDN, privately. */
#define SOCKS_COMMAND_RESOLVE_PTR 0xF1 #define SOCKS_COMMAND_RESOLVE_PTR 0xF1
#define SOCKS_COMMAND_IS_CONNECT(c) ((c)==SOCKS_COMMAND_CONNECT) /* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */
#define SOCKS_COMMAND_IS_CONNECT(c) (((c)==SOCKS_COMMAND_CONNECT) || 0)
#define SOCKS_COMMAND_IS_RESOLVE(c) ((c)==SOCKS_COMMAND_RESOLVE || \ #define SOCKS_COMMAND_IS_RESOLVE(c) ((c)==SOCKS_COMMAND_RESOLVE || \
(c)==SOCKS_COMMAND_RESOLVE_PTR) (c)==SOCKS_COMMAND_RESOLVE_PTR)