mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
Add a bunch more warnings to out warning suite; resolve them; pack structs a little better.
svn:r5150
This commit is contained in:
parent
c6347cdb0e
commit
5c53545d81
@ -115,7 +115,7 @@ _aes_fill_buf(aes_cnt_cipher_t *cipher)
|
|||||||
* Return a newly allocated counter-mode AES128 cipher implementation.
|
* Return a newly allocated counter-mode AES128 cipher implementation.
|
||||||
*/
|
*/
|
||||||
aes_cnt_cipher_t*
|
aes_cnt_cipher_t*
|
||||||
aes_new_cipher()
|
aes_new_cipher(void)
|
||||||
{
|
{
|
||||||
aes_cnt_cipher_t* result = tor_malloc_zero(sizeof(aes_cnt_cipher_t));
|
aes_cnt_cipher_t* result = tor_malloc_zero(sizeof(aes_cnt_cipher_t));
|
||||||
|
|
||||||
|
@ -817,7 +817,7 @@ spawn_func(int (*func)(void *), void *data)
|
|||||||
/** End the current thread/process.
|
/** End the current thread/process.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
spawn_exit()
|
spawn_exit(void)
|
||||||
{
|
{
|
||||||
#if defined(USE_WIN32_THREADS)
|
#if defined(USE_WIN32_THREADS)
|
||||||
_endthread();
|
_endthread();
|
||||||
|
@ -43,7 +43,7 @@ struct smartlist_t {
|
|||||||
/** Allocate and return an empty smartlist.
|
/** Allocate and return an empty smartlist.
|
||||||
*/
|
*/
|
||||||
smartlist_t *
|
smartlist_t *
|
||||||
smartlist_create() {
|
smartlist_create(void) {
|
||||||
smartlist_t *sl = tor_malloc(sizeof(smartlist_t));
|
smartlist_t *sl = tor_malloc(sizeof(smartlist_t));
|
||||||
sl->num_used = 0;
|
sl->num_used = 0;
|
||||||
sl->capacity = SMARTLIST_DEFAULT_CAPACITY;
|
sl->capacity = SMARTLIST_DEFAULT_CAPACITY;
|
||||||
|
@ -216,7 +216,7 @@ crypto_global_init(int useAccel)
|
|||||||
|
|
||||||
/** Uninitialize the crypto library. Return 0 on success, -1 on failure.
|
/** Uninitialize the crypto library. Return 0 on success, -1 on failure.
|
||||||
*/
|
*/
|
||||||
int crypto_global_cleanup()
|
int crypto_global_cleanup(void)
|
||||||
{
|
{
|
||||||
ERR_free_strings();
|
ERR_free_strings();
|
||||||
#ifndef NO_ENGINES
|
#ifndef NO_ENGINES
|
||||||
@ -354,7 +354,7 @@ crypto_create_init_cipher(const char *key, int encrypt_mode)
|
|||||||
|
|
||||||
/** Allocate and return a new symmetric cipher.
|
/** Allocate and return a new symmetric cipher.
|
||||||
*/
|
*/
|
||||||
crypto_cipher_env_t *crypto_new_cipher_env()
|
crypto_cipher_env_t *crypto_new_cipher_env(void)
|
||||||
{
|
{
|
||||||
crypto_cipher_env_t *env;
|
crypto_cipher_env_t *env;
|
||||||
|
|
||||||
@ -1303,7 +1303,7 @@ static void init_dh_param(void) {
|
|||||||
|
|
||||||
/** Allocate and return a new DH object for a key exchange.
|
/** Allocate and return a new DH object for a key exchange.
|
||||||
*/
|
*/
|
||||||
crypto_dh_env_t *crypto_dh_new()
|
crypto_dh_env_t *crypto_dh_new(void)
|
||||||
{
|
{
|
||||||
crypto_dh_env_t *res = NULL;
|
crypto_dh_env_t *res = NULL;
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ void _log_fn(int severity, const char *format, ...)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Close all open log files. */
|
/** Close all open log files. */
|
||||||
void close_logs()
|
void close_logs(void)
|
||||||
{
|
{
|
||||||
logfile_t *victim;
|
logfile_t *victim;
|
||||||
while (logfiles) {
|
while (logfiles) {
|
||||||
@ -271,7 +271,7 @@ void close_logs()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Close and re-open all log files; used to rotate logs on SIGHUP. */
|
/** Close and re-open all log files; used to rotate logs on SIGHUP. */
|
||||||
void reset_logs()
|
void reset_logs(void)
|
||||||
{
|
{
|
||||||
logfile_t *lf = logfiles;
|
logfile_t *lf = logfiles;
|
||||||
while (lf) {
|
while (lf) {
|
||||||
|
@ -177,6 +177,9 @@ tor_tls_free_all(void)
|
|||||||
static int always_accept_verify_cb(int preverify_ok,
|
static int always_accept_verify_cb(int preverify_ok,
|
||||||
X509_STORE_CTX *x509_ctx)
|
X509_STORE_CTX *x509_ctx)
|
||||||
{
|
{
|
||||||
|
/* avoid "unused parameter" warning. */
|
||||||
|
preverify_ok = 0;
|
||||||
|
x509_ctx = NULL;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@ const char util_c_id[] = "$Id$";
|
|||||||
* ===== */
|
* ===== */
|
||||||
#ifdef USE_DMALLOC
|
#ifdef USE_DMALLOC
|
||||||
#include <dmalloc.h>
|
#include <dmalloc.h>
|
||||||
|
#define DMALLOC_FN_ARGS file, line,
|
||||||
#else
|
#else
|
||||||
#define dmalloc_strdup(file, line, string, xalloc_b) strdup(string)
|
#define dmalloc_strdup(file, line, string, xalloc_b) strdup(string)
|
||||||
|
|
||||||
@ -104,6 +105,7 @@ const char util_c_id[] = "$Id$";
|
|||||||
|
|
||||||
#define dmalloc_realloc(file, line, old_pnt, new_size, func_id, xalloc_b) realloc((old_pnt), (new_size))
|
#define dmalloc_realloc(file, line, old_pnt, new_size, func_id, xalloc_b) realloc((old_pnt), (new_size))
|
||||||
#define DMALLOC_FUNC_REALLOC 0
|
#define DMALLOC_FUNC_REALLOC 0
|
||||||
|
#define DMALLOC_FN_ARGS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Allocate a chunk of <b>size</b> bytes of memory, and return a pointer to
|
/** Allocate a chunk of <b>size</b> bytes of memory, and return a pointer to
|
||||||
@ -113,7 +115,8 @@ const char util_c_id[] = "$Id$";
|
|||||||
* <b>file</b> and <b>line</b> are used if dmalloc is enabled, and
|
* <b>file</b> and <b>line</b> are used if dmalloc is enabled, and
|
||||||
* ignored otherwise.
|
* ignored otherwise.
|
||||||
*/
|
*/
|
||||||
void *_tor_malloc(const char *file, const int line, size_t size) {
|
void *_tor_malloc(DMALLOC_PARAMS size_t size)
|
||||||
|
{
|
||||||
void *result;
|
void *result;
|
||||||
|
|
||||||
/* Some libcs don't do the right thing on size==0. Override them. */
|
/* Some libcs don't do the right thing on size==0. Override them. */
|
||||||
@ -136,8 +139,8 @@ void *_tor_malloc(const char *file, const int line, size_t size) {
|
|||||||
* zero bytes, and return a pointer to the result. Log and terminate
|
* zero bytes, and return a pointer to the result. Log and terminate
|
||||||
* the process on error. (Same as calloc(size,1), but never returns NULL.)
|
* the process on error. (Same as calloc(size,1), but never returns NULL.)
|
||||||
*/
|
*/
|
||||||
void *_tor_malloc_zero(const char *file, const int line, size_t size) {
|
void *_tor_malloc_zero(DMALLOC_PARAMS size_t size) {
|
||||||
void *result = _tor_malloc(file, line, size);
|
void *result = _tor_malloc(DMALLOC_FN_ARGS size);
|
||||||
memset(result, 0, size);
|
memset(result, 0, size);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -146,7 +149,7 @@ void *_tor_malloc_zero(const char *file, const int line, size_t size) {
|
|||||||
* bytes long; return the new memory block. On error, log and
|
* bytes long; return the new memory block. On error, log and
|
||||||
* terminate. (Like realloc(ptr,size), but never returns NULL.)
|
* terminate. (Like realloc(ptr,size), but never returns NULL.)
|
||||||
*/
|
*/
|
||||||
void *_tor_realloc(const char *file, const int line, void *ptr, size_t size) {
|
void *_tor_realloc(DMALLOC_PARAMS void *ptr, size_t size) {
|
||||||
void *result;
|
void *result;
|
||||||
|
|
||||||
result = dmalloc_realloc(file, line, ptr, size, DMALLOC_FUNC_REALLOC, 0);
|
result = dmalloc_realloc(file, line, ptr, size, DMALLOC_FUNC_REALLOC, 0);
|
||||||
@ -161,7 +164,7 @@ void *_tor_realloc(const char *file, const int line, void *ptr, size_t size) {
|
|||||||
* error, log and terminate. (Like strdup(s), but never returns
|
* error, log and terminate. (Like strdup(s), but never returns
|
||||||
* NULL.)
|
* NULL.)
|
||||||
*/
|
*/
|
||||||
char *_tor_strdup(const char *file, const int line, const char *s) {
|
char *_tor_strdup(DMALLOC_PARAMS const char *s) {
|
||||||
char *dup;
|
char *dup;
|
||||||
tor_assert(s);
|
tor_assert(s);
|
||||||
|
|
||||||
@ -179,10 +182,10 @@ char *_tor_strdup(const char *file, const int line, const char *s) {
|
|||||||
* always NUL-terminated. (Like strndup(s,n), but never returns
|
* always NUL-terminated. (Like strndup(s,n), but never returns
|
||||||
* NULL.)
|
* NULL.)
|
||||||
*/
|
*/
|
||||||
char *_tor_strndup(const char *file, const int line, const char *s, size_t n) {
|
char *_tor_strndup(DMALLOC_PARAMS const char *s, size_t n) {
|
||||||
char *dup;
|
char *dup;
|
||||||
tor_assert(s);
|
tor_assert(s);
|
||||||
dup = _tor_malloc(file, line, n+1);
|
dup = _tor_malloc(DMALLOC_FN_ARGS n+1);
|
||||||
/* Performance note: Ordinarily we prefer strlcpy to strncpy. But
|
/* Performance note: Ordinarily we prefer strlcpy to strncpy. But
|
||||||
* this function gets called a whole lot, and platform strncpy is
|
* this function gets called a whole lot, and platform strncpy is
|
||||||
* much faster than strlcpy when strlen(s) is much longer than n.
|
* much faster than strlcpy when strlen(s) is much longer than n.
|
||||||
|
@ -47,24 +47,32 @@
|
|||||||
} } while (0)
|
} } while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_DMALLOC
|
||||||
|
#define DMALLOC_PARAMS const char *file, const int line,
|
||||||
|
#define DMALLOC_ARGS _SHORT_FILE_, __LINE__,
|
||||||
|
#else
|
||||||
|
#define DMALLOC_PARAMS
|
||||||
|
#define DMALLOC_ARGS
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Define this if you want Tor to crash when any problem comes up,
|
/** Define this if you want Tor to crash when any problem comes up,
|
||||||
* so you can get a coredump and track things down. */
|
* so you can get a coredump and track things down. */
|
||||||
// #define tor_fragile_assert() tor_assert(0)
|
// #define tor_fragile_assert() tor_assert(0)
|
||||||
#define tor_fragile_assert()
|
#define tor_fragile_assert()
|
||||||
|
|
||||||
/* Memory management */
|
/* Memory management */
|
||||||
void *_tor_malloc(const char *file, const int line, size_t size);
|
void *_tor_malloc(DMALLOC_PARAMS size_t size);
|
||||||
void *_tor_malloc_zero(const char *file, const int line, size_t size);
|
void *_tor_malloc_zero(DMALLOC_PARAMS size_t size);
|
||||||
void *_tor_realloc(const char *file, const int line, void *ptr, size_t size);
|
void *_tor_realloc(DMALLOC_PARAMS void *ptr, size_t size);
|
||||||
char *_tor_strdup(const char *file, const int line, const char *s);
|
char *_tor_strdup(DMALLOC_PARAMS const char *s);
|
||||||
char *_tor_strndup(const char *file, const int line, const char *s, size_t n);
|
char *_tor_strndup(DMALLOC_PARAMS const char *s, size_t n);
|
||||||
#define tor_free(p) do { if (p) {free(p); (p)=NULL;} } while (0)
|
#define tor_free(p) do { if (p) {free(p); (p)=NULL;} } while (0)
|
||||||
|
|
||||||
#define tor_malloc(size) _tor_malloc(_SHORT_FILE_, __LINE__, size)
|
#define tor_malloc(size) _tor_malloc(DMALLOC_ARGS size)
|
||||||
#define tor_malloc_zero(size) _tor_malloc_zero(_SHORT_FILE_, __LINE__, size)
|
#define tor_malloc_zero(size) _tor_malloc_zero(DMALLOC_ARGS size)
|
||||||
#define tor_realloc(ptr, size) _tor_realloc(_SHORT_FILE_, __LINE__, ptr, size)
|
#define tor_realloc(ptr, size) _tor_realloc(DMALLOC_ARGS ptr, size)
|
||||||
#define tor_strdup(s) _tor_strdup(_SHORT_FILE_, __LINE__, s)
|
#define tor_strdup(s) _tor_strdup(DMALLOC_ARGS s)
|
||||||
#define tor_strndup(s, n) _tor_strndup(_SHORT_FILE_, __LINE__, s, n)
|
#define tor_strndup(s, n) _tor_strndup(DMALLOC_ARGS s, n)
|
||||||
|
|
||||||
/* String manipulation */
|
/* String manipulation */
|
||||||
#define HEX_CHARACTERS "0123456789ABCDEFabcdef"
|
#define HEX_CHARACTERS "0123456789ABCDEFabcdef"
|
||||||
|
@ -979,6 +979,8 @@ circuit_all_predicted_ports_handled(time_t now, int *need_uptime,
|
|||||||
uint16_t *port;
|
uint16_t *port;
|
||||||
smartlist_t *sl = circuit_get_unhandled_ports(now);
|
smartlist_t *sl = circuit_get_unhandled_ports(now);
|
||||||
smartlist_t *LongLivedServices = get_options()->LongLivedPorts;
|
smartlist_t *LongLivedServices = get_options()->LongLivedPorts;
|
||||||
|
tor_assert(need_uptime);
|
||||||
|
tor_assert(need_capacity);
|
||||||
enough = (smartlist_len(sl) == 0);
|
enough = (smartlist_len(sl) == 0);
|
||||||
for (i = 0; i < smartlist_len(sl); ++i) {
|
for (i = 0; i < smartlist_len(sl); ++i) {
|
||||||
port = smartlist_get(sl, i);
|
port = smartlist_get(sl, i);
|
||||||
@ -1380,6 +1382,8 @@ choose_good_middle_server(uint8_t purpose,
|
|||||||
routerinfo_t *r, *choice;
|
routerinfo_t *r, *choice;
|
||||||
crypt_path_t *cpath;
|
crypt_path_t *cpath;
|
||||||
smartlist_t *excluded;
|
smartlist_t *excluded;
|
||||||
|
tor_assert(_CIRCUIT_PURPOSE_MIN <= purpose &&
|
||||||
|
purpose <= _CIRCUIT_PURPOSE_MAX);
|
||||||
|
|
||||||
log_fn(LOG_DEBUG, "Contemplating intermediate hop: random choice.");
|
log_fn(LOG_DEBUG, "Contemplating intermediate hop: random choice.");
|
||||||
excluded = smartlist_create();
|
excluded = smartlist_create();
|
||||||
|
@ -2000,8 +2000,10 @@ assert_connection_ok(connection_t *conn, time_t now)
|
|||||||
tor_assert(!conn->cpath_layer);
|
tor_assert(!conn->cpath_layer);
|
||||||
tor_assert(!conn->package_window);
|
tor_assert(!conn->package_window);
|
||||||
tor_assert(!conn->deliver_window);
|
tor_assert(!conn->deliver_window);
|
||||||
|
#if 0
|
||||||
tor_assert(!conn->done_sending);
|
tor_assert(!conn->done_sending);
|
||||||
tor_assert(!conn->done_receiving);
|
tor_assert(!conn->done_receiving);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* XXX unchecked: package window, deliver window. */
|
/* XXX unchecked: package window, deliver window. */
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,7 @@ dirserv_get_nickname_by_digest(const char *digest)
|
|||||||
|
|
||||||
/** Clear the current fingerprint list. */
|
/** Clear the current fingerprint list. */
|
||||||
void
|
void
|
||||||
dirserv_free_fingerprint_list()
|
dirserv_free_fingerprint_list(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
fingerprint_entry_t *ent;
|
fingerprint_entry_t *ent;
|
||||||
@ -555,7 +555,7 @@ dirserver_getinfo_unregistered(const char *question)
|
|||||||
* generated one.
|
* generated one.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
directory_set_dirty()
|
directory_set_dirty(void)
|
||||||
{
|
{
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
||||||
|
37
src/or/or.h
37
src/or/or.h
@ -591,24 +591,29 @@ struct connection_t {
|
|||||||
uint8_t type; /**< What kind of connection is this? */
|
uint8_t type; /**< What kind of connection is this? */
|
||||||
uint8_t state; /**< Current state of this connection. */
|
uint8_t state; /**< Current state of this connection. */
|
||||||
uint8_t purpose; /**< Only used for DIR types currently. */
|
uint8_t purpose; /**< Only used for DIR types currently. */
|
||||||
uint8_t wants_to_read; /**< Boolean: should we start reading again once
|
unsigned wants_to_read:1; /**< Boolean: should we start reading again once
|
||||||
* the bandwidth throttler allows it?
|
* the bandwidth throttler allows it?
|
||||||
*/
|
*/
|
||||||
uint8_t wants_to_write; /**< Boolean: should we start writing again once
|
unsigned wants_to_write:1; /**< Boolean: should we start writing again once
|
||||||
* the bandwidth throttler allows reads?
|
* the bandwidth throttler allows reads?
|
||||||
*/
|
*/
|
||||||
|
unsigned marked_for_close:1; /**< Boolean: should we close this conn on the
|
||||||
|
* next iteration of the main loop?
|
||||||
|
*/
|
||||||
|
unsigned hold_open_until_flushed:1; /**< Despite this connection's being
|
||||||
|
* marked for close, do we flush it
|
||||||
|
* before closing it?
|
||||||
|
*/
|
||||||
|
unsigned has_sent_end:1; /**< For debugging; only used on edge connections.
|
||||||
|
* Set once we've set the stream end,
|
||||||
|
* and check in circuit_about_to_close_connection(). */
|
||||||
|
|
||||||
int s; /**< Our socket; -1 if this connection is closed. */
|
int s; /**< Our socket; -1 if this connection is closed. */
|
||||||
int poll_index; /* XXXX rename. */
|
int poll_index; /* XXXX rename. */
|
||||||
struct event *read_event; /**< libevent event structure. */
|
struct event *read_event; /**< libevent event structure. */
|
||||||
struct event *write_event; /**< libevent event structure. */
|
struct event *write_event; /**< libevent event structure. */
|
||||||
int marked_for_close; /**< Boolean: should we close this conn on the next
|
|
||||||
* iteration of the main loop?
|
|
||||||
*/
|
|
||||||
const char *marked_for_close_file; /**< For debugging: in which file were
|
const char *marked_for_close_file; /**< For debugging: in which file were
|
||||||
* we marked for close? */
|
* we marked for close? */
|
||||||
int hold_open_until_flushed; /**< Despite this connection's being marked
|
|
||||||
* for close, do we flush it before closing it?
|
|
||||||
*/
|
|
||||||
|
|
||||||
buf_t *inbuf; /**< Buffer holding data read over this connection. */
|
buf_t *inbuf; /**< Buffer holding data read over this connection. */
|
||||||
int inbuf_reached_eof; /**< Boolean: did read() return 0 on this conn? */
|
int inbuf_reached_eof; /**< Boolean: did read() return 0 on this conn? */
|
||||||
@ -668,10 +673,10 @@ struct connection_t {
|
|||||||
int deliver_window; /**< How many more relay cells can end at me? (Edge
|
int deliver_window; /**< How many more relay cells can end at me? (Edge
|
||||||
* only.) */
|
* only.) */
|
||||||
|
|
||||||
|
#if 0
|
||||||
int done_sending; /**< For half-open connections; not used currently. */
|
int done_sending; /**< For half-open connections; not used currently. */
|
||||||
int done_receiving; /**< For half-open connections; not used currently. */
|
int done_receiving; /**< For half-open connections; not used currently. */
|
||||||
char has_sent_end; /**< For debugging: set once we've set the stream end,
|
#endif
|
||||||
and check in circuit_about_to_close_connection(). */
|
|
||||||
struct circuit_t *on_circuit; /**< The circuit (if any) that this edge
|
struct circuit_t *on_circuit; /**< The circuit (if any) that this edge
|
||||||
* connection is using. */
|
* connection is using. */
|
||||||
|
|
||||||
@ -805,9 +810,9 @@ typedef struct routerstatus_t {
|
|||||||
/** DOCDOC */
|
/** DOCDOC */
|
||||||
typedef struct local_routerstatus_t {
|
typedef struct local_routerstatus_t {
|
||||||
routerstatus_t status;
|
routerstatus_t status;
|
||||||
|
time_t next_attempt_at; /**< When should we try this descriptor again? */
|
||||||
uint8_t n_download_failures; /**< Number of failures trying to download the
|
uint8_t n_download_failures; /**< Number of failures trying to download the
|
||||||
* most recent descriptor. */
|
* most recent descriptor. */
|
||||||
time_t next_attempt_at; /**< When should we try this descriptor again? */
|
|
||||||
unsigned int should_download:1; /**< DOCDOC */
|
unsigned int should_download:1; /**< DOCDOC */
|
||||||
} local_routerstatus_t;
|
} local_routerstatus_t;
|
||||||
|
|
||||||
@ -1101,9 +1106,9 @@ typedef struct exit_redirect_t {
|
|||||||
uint16_t port_min;
|
uint16_t port_min;
|
||||||
uint16_t port_max;
|
uint16_t port_max;
|
||||||
|
|
||||||
int is_redirect;
|
|
||||||
uint32_t addr_dest;
|
uint32_t addr_dest;
|
||||||
uint16_t port_dest;
|
uint16_t port_dest;
|
||||||
|
unsigned is_redirect:1;
|
||||||
} exit_redirect_t;
|
} exit_redirect_t;
|
||||||
|
|
||||||
typedef struct config_line_t {
|
typedef struct config_line_t {
|
||||||
|
Loading…
Reference in New Issue
Block a user