diff --git a/src/or/buffers.c b/src/or/buffers.c index 6b30d13f0f..afb3020970 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -22,13 +22,12 @@ struct buf_t { * out smaller than this, but they will never autoshrink to less * than this size. */ #define MIN_BUF_SHRINK_SIZE (16*1024) -#define BUF_OK(b) ((b) && (b)->mem && (b)->datalen <= (b)->len) /* Change a buffer's capacity. Must only be called when */ static INLINE void buf_resize(buf_t *buf, size_t new_capacity) { - assert(buf->datalen <= new_capacity); - assert(new_capacity); + tor_assert(buf->datalen <= new_capacity); + tor_assert(new_capacity); buf->mem = tor_realloc(buf->mem, new_capacity); buf->len = new_capacity; } @@ -83,7 +82,7 @@ static INLINE void buf_shrink_if_underfull(buf_t *buf) { /* Remove the first 'n' bytes from buf. */ static INLINE void buf_remove_from_front(buf_t *buf, size_t n) { - assert(buf->datalen >= n); + tor_assert(buf->datalen >= n); buf->datalen -= n; memmove(buf->mem, buf->mem+n, buf->datalen); buf_shrink_if_underfull(buf); @@ -99,7 +98,7 @@ static int find_str_in_str(const char *str, int str_len, const char *location; const char *last_possible = buf + buf_len - str_len; - assert(str && str_len > 0 && buf); + tor_assert(str && str_len > 0 && buf); if(buf_len < str_len) return -1; @@ -126,7 +125,7 @@ buf_t *buf_new_with_capacity(size_t size) { buf->datalen = 0; // memset(buf->mem,0,size); - assert(BUF_OK(buf)); + assert_buf_ok(buf); return buf; } @@ -176,7 +175,8 @@ int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof) { int e; #endif - assert(BUF_OK(buf) && reached_eof && (s>=0)); + assert_buf_ok(buf); + tor_assert(reached_eof && (s>=0)); if (buf_ensure_capacity(buf,buf->datalen+at_most)) return -1; @@ -214,7 +214,8 @@ int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof) { int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf) { int r; - assert(tls && BUF_OK(buf)); + tor_assert(tls); + assert_buf_ok(buf); if (buf_ensure_capacity(buf, at_most+buf->datalen)) return -1; @@ -245,7 +246,8 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen) int e; #endif - assert(BUF_OK(buf) && buf_flushlen && (s>=0) && (*buf_flushlen <= buf->datalen)); + assert_buf_ok(buf); + tor_assert(buf_flushlen && (s>=0) && (*buf_flushlen <= buf->datalen)); if(*buf_flushlen == 0) /* nothing to flush */ return 0; @@ -253,7 +255,7 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen) write_result = send(s, buf->mem, *buf_flushlen, 0); if (write_result < 0) { if(!ERRNO_EAGAIN(errno)) { /* it's a real error */ - assert(errno != EPIPE); /* get a stack trace to find epipe bugs */ + tor_assert(errno != EPIPE); /* get a stack trace to find epipe bugs */ return -1; } #ifdef MS_WINDOWS @@ -277,7 +279,8 @@ 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 r; - assert(tls && BUF_OK(buf) && buf_flushlen); + assert_buf_ok(buf); + tor_assert(tls && buf_flushlen); /* we want to let tls write even if flushlen is zero, because it might * have a partial record pending */ @@ -298,7 +301,8 @@ int write_to_buf(const char *string, int string_len, buf_t *buf) { * return total number of bytes on the buf */ - assert(string && BUF_OK(buf)); + tor_assert(string); + assert_buf_ok(buf); if (buf_ensure_capacity(buf, buf->datalen+string_len)) { log_fn(LOG_WARN, "buflen too small, can't hold %d bytes.", (int)buf->datalen+string_len); @@ -318,8 +322,9 @@ int fetch_from_buf(char *string, int string_len, buf_t *buf) { * * Return the number of bytes still on the buffer. */ - assert(string && BUF_OK(buf)); - assert(string_len <= buf->datalen); /* make sure we don't ask for too much */ + tor_assert(string); + tor_assert(string_len <= buf->datalen); /* make sure we don't ask for too much */ + assert_buf_ok(buf); memcpy(string,buf->mem,string_len); buf_remove_from_front(buf, string_len); @@ -347,7 +352,7 @@ int fetch_from_buf_http(buf_t *buf, int i; int headerlen, bodylen, contentlen; - assert(BUF_OK(buf)); + assert_buf_ok(buf); headers = buf->mem; i = find_on_inbuf("\r\n\r\n", 4, buf); @@ -390,7 +395,7 @@ int fetch_from_buf_http(buf_t *buf, (*headers_out)[headerlen] = 0; /* null terminate it */ } if(body_out) { - assert(body_used); + tor_assert(body_used); *body_used = bodylen; *body_out = tor_malloc(bodylen+1); memcpy(*body_out,buf->mem+headerlen,bodylen); @@ -431,7 +436,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { if(req->socks_version != 5) { /* we need to negotiate a method */ unsigned char nummethods = (unsigned char)*(buf->mem+1); - assert(!req->socks_version); + tor_assert(!req->socks_version); if(buf->datalen < 2+nummethods) return 0; if(!nummethods || !memchr(buf->mem+2, 0, nummethods)) { @@ -494,7 +499,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { log_fn(LOG_WARN,"socks5: unsupported address type %d. Rejecting.",*(buf->mem+3)); return -1; } - assert(0); + tor_assert(0); case 4: /* socks4 */ /* http://archive.socks.permeo.com/protocol/socks4.protocol */ /* http://archive.socks.permeo.com/protocol/socks4a.protocol */ @@ -587,14 +592,16 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { } } + void assert_buf_ok(buf_t *buf) { - assert(buf); - assert(buf->magic == BUFFER_MAGIC); - assert(buf->mem); - assert(buf->datalen <= buf->len); + tor_assert(buf); + tor_assert(buf->magic == BUFFER_MAGIC); + tor_assert(buf->mem); + tor_assert(buf->datalen <= buf->len); } + /* Local Variables: mode:c diff --git a/src/or/circuit.c b/src/or/circuit.c index 5a5aa1efe1..b65bc3270c 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -51,7 +51,7 @@ void circuit_add(circuit_t *circ) { void circuit_remove(circuit_t *circ) { circuit_t *tmpcirc; - assert(circ && global_circuitlist); + tor_assert(circ && global_circuitlist); if(global_circuitlist == circ) { global_circuitlist = global_circuitlist->next; @@ -120,8 +120,8 @@ circuit_t *circuit_new(uint16_t p_circ_id, connection_t *p_conn) { } void circuit_free(circuit_t *circ) { - assert(circ); - assert(circ->magic == CIRCUIT_MAGIC); + tor_assert(circ); + tor_assert(circ->magic == CIRCUIT_MAGIC); if (circ->n_crypto) crypto_free_cipher_env(circ->n_crypto); if (circ->p_crypto) @@ -182,7 +182,7 @@ static uint16_t get_unique_circ_id_by_conn(connection_t *conn, int circ_id_type) int attempts=0; uint16_t high_bit; - assert(conn && conn->type == CONN_TYPE_OR); + tor_assert(conn && conn->type == CONN_TYPE_OR); high_bit = (circ_id_type == CIRC_ID_TYPE_HIGHER) ? 1<<15 : 0; do { /* Sequentially iterate over test_circ_id=1...1<<15-1 until we find a @@ -377,11 +377,11 @@ circuit_t *circuit_get_best(connection_t *conn, circuit_t *circ, *best=NULL; time_t now = time(NULL); - assert(conn); + tor_assert(conn); - assert(purpose == CIRCUIT_PURPOSE_C_GENERAL || - purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT || - purpose == CIRCUIT_PURPOSE_C_REND_JOINED); + tor_assert(purpose == CIRCUIT_PURPOSE_C_GENERAL || + purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT || + purpose == CIRCUIT_PURPOSE_C_REND_JOINED); for (circ=global_circuitlist;circ;circ = circ->next) { if (!circuit_is_acceptable(circ,conn,must_be_open,purpose,now)) @@ -705,8 +705,8 @@ int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ, crypt_path_t *layer_hint=NULL; char recognized=0; - assert(cell && circ); - assert(cell_direction == CELL_DIRECTION_OUT || cell_direction == CELL_DIRECTION_IN); + tor_assert(cell && circ); + tor_assert(cell_direction == CELL_DIRECTION_OUT || cell_direction == CELL_DIRECTION_IN); if (circ->marked_for_close) return 0; @@ -747,8 +747,8 @@ int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ, if(!conn) { if (circ->rend_splice && cell_direction == CELL_DIRECTION_OUT) { - assert(circ->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED); - assert(circ->rend_splice->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED); + tor_assert(circ->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED); + tor_assert(circ->rend_splice->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED); cell->circ_id = circ->rend_splice->p_circ_id; if (circuit_receive_relay_cell(cell, circ->rend_splice, CELL_DIRECTION_IN)<0) { log_fn(LOG_WARN, "Error relaying cell across rendezvous; closing circuits"); @@ -773,20 +773,20 @@ static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction, crypt_path_t *thishop; relay_header_t rh; - assert(circ && cell && recognized); - assert(cell_direction == CELL_DIRECTION_IN || cell_direction == CELL_DIRECTION_OUT); + tor_assert(circ && cell && recognized); + tor_assert(cell_direction == CELL_DIRECTION_IN || cell_direction == CELL_DIRECTION_OUT); if(cell_direction == CELL_DIRECTION_IN) { if(CIRCUIT_IS_ORIGIN(circ)) { /* we're at the beginning of the circuit. We'll want to do layered crypts. */ - assert(circ->cpath); + tor_assert(circ->cpath); thishop = circ->cpath; if(thishop->state != CPATH_STATE_OPEN) { log_fn(LOG_WARN,"Relay cell before first created cell? Closing."); return -1; } do { /* Remember: cpath is in forward order, that is, first hop first. */ - assert(thishop); + tor_assert(thishop); if(relay_crypt_one_payload(thishop->b_crypto, cell->payload, 0) < 0) return -1; @@ -852,7 +852,7 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ, thishop = layer_hint; /* moving from farthest to nearest hop */ do { - assert(thishop); + tor_assert(thishop); log_fn(LOG_DEBUG,"crypting a layer of the relay cell."); if(relay_crypt_one_payload(thishop->f_crypto, cell->payload, 1) < 0) { @@ -1002,7 +1002,7 @@ int _circuit_mark_for_close(circuit_t *circ) { circuit_rep_hist_note_result(circ); } if (circ->purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) { - assert(circ->state == CIRCUIT_STATE_OPEN); + tor_assert(circ->state == CIRCUIT_STATE_OPEN); /* treat this like getting a nack from it */ log_fn(LOG_INFO,"Failed intro circ %s to %s (awaiting ack). Removing from descriptor.", circ->rend_query, circ->build_state->chosen_exit); @@ -1033,8 +1033,7 @@ int _circuit_mark_for_close(circuit_t *circ) { void circuit_detach_stream(circuit_t *circ, connection_t *conn) { connection_t *prevconn; - assert(circ); - assert(conn); + tor_assert(circ && conn); if(conn == circ->p_streams) { circ->p_streams = conn->next_stream; @@ -1055,7 +1054,7 @@ void circuit_detach_stream(circuit_t *circ, connection_t *conn) { return; } log_fn(LOG_ERR,"edge conn not in circuit's list?"); - assert(0); /* should never get here */ + tor_assert(0); /* should never get here */ } void circuit_about_to_close_connection(connection_t *conn) { @@ -1104,7 +1103,7 @@ void circuit_log_path(int severity, circuit_t *circ) { struct crypt_path_t *hop; char *states[] = {"closed", "waiting for keys", "open"}; routerinfo_t *router; - assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath); + tor_assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath); snprintf(s, sizeof(buf)-1, "circ (length %d, exit %s): ", circ->build_state->desired_path_len, circ->build_state->chosen_exit); @@ -1277,7 +1276,7 @@ static void circuit_is_open(circuit_t *circ) { break; default: log_fn(LOG_ERR,"unhandled purpose %d",circ->purpose); - assert(0); + tor_assert(0); } } @@ -1344,7 +1343,7 @@ static void circuit_build_failed(circuit_t *circ) { default: /* Other cases are impossible, since this function is only called with * unbuilt circuits. */ - assert(0); + tor_assert(0); } } @@ -1448,7 +1447,7 @@ void circuit_n_conn_open(connection_t *or_conn) { if (circ->marked_for_close) continue; if(CIRCUIT_IS_ORIGIN(circ) && circ->n_addr == or_conn->addr && circ->n_port == or_conn->port) { - assert(circ->state == CIRCUIT_STATE_OR_WAIT); + tor_assert(circ->state == CIRCUIT_STATE_OR_WAIT); log_fn(LOG_DEBUG,"Found circ %d, sending onion skin.", circ->n_circ_id); circ->n_conn = or_conn; if(circuit_send_next_onion_skin(circ) < 0) { @@ -1471,10 +1470,10 @@ int circuit_send_next_onion_skin(circuit_t *circ) { int circ_id_type; char payload[2+4+ONIONSKIN_CHALLENGE_LEN]; - assert(circ && CIRCUIT_IS_ORIGIN(circ)); + tor_assert(circ && CIRCUIT_IS_ORIGIN(circ)); if(circ->cpath->state == CPATH_STATE_CLOSED) { - assert(circ->n_conn && circ->n_conn->type == CONN_TYPE_OR); + tor_assert(circ->n_conn && circ->n_conn->type == CONN_TYPE_OR); log_fn(LOG_DEBUG,"First skin; sending create cell."); circ_id_type = decide_circ_id_type(options.Nickname, @@ -1505,8 +1504,8 @@ int circuit_send_next_onion_skin(circuit_t *circ) { circ->state = CIRCUIT_STATE_BUILDING; log_fn(LOG_DEBUG,"first skin; finished sending create cell."); } else { - assert(circ->cpath->state == CPATH_STATE_OPEN); - assert(circ->state == CIRCUIT_STATE_BUILDING); + tor_assert(circ->cpath->state == CPATH_STATE_OPEN); + tor_assert(circ->state == CIRCUIT_STATE_BUILDING); log_fn(LOG_DEBUG,"starting to send subsequent skin."); r = onion_extend_cpath(&circ->cpath, circ->build_state, &router); if (r==1) { @@ -1622,9 +1621,9 @@ int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data, int reverse) crypto_digest_env_t *tmp_digest; crypto_cipher_env_t *tmp_crypto; - assert(cpath && key_data); - assert(!(cpath->f_crypto || cpath->b_crypto || - cpath->f_digest || cpath->b_digest)); + tor_assert(cpath && key_data); + tor_assert(!(cpath->f_crypto || cpath->b_crypto || + cpath->f_digest || cpath->b_digest)); memset(iv, 0, CIPHER_IV_LEN); @@ -1664,7 +1663,7 @@ int circuit_finish_handshake(circuit_t *circ, char *reply) { unsigned char keys[CPATH_KEY_MATERIAL_LEN]; crypt_path_t *hop; - assert(CIRCUIT_IS_ORIGIN(circ)); + tor_assert(CIRCUIT_IS_ORIGIN(circ)); if(circ->cpath->state == CPATH_STATE_AWAITING_KEYS) hop = circ->cpath; else { @@ -1676,7 +1675,7 @@ int circuit_finish_handshake(circuit_t *circ, char *reply) { return -1; } } - assert(hop->state == CPATH_STATE_AWAITING_KEYS); + tor_assert(hop->state == CPATH_STATE_AWAITING_KEYS); if(onion_skin_client_handshake(hop->handshake_state, reply, keys, DIGEST_LEN*2+CIPHER_KEY_LEN*2) < 0) { @@ -1703,8 +1702,8 @@ int circuit_truncated(circuit_t *circ, crypt_path_t *layer) { crypt_path_t *victim; connection_t *stream; - assert(circ && CIRCUIT_IS_ORIGIN(circ)); - assert(layer); + tor_assert(circ && CIRCUIT_IS_ORIGIN(circ)); + tor_assert(layer); /* XXX Since we don't ask for truncates currently, getting a truncated * means that a connection broke or an extend failed. For now, @@ -1738,24 +1737,24 @@ int circuit_truncated(circuit_t *circ, crypt_path_t *layer) { void assert_cpath_layer_ok(const crypt_path_t *cp) { - assert(cp->f_crypto); - assert(cp->b_crypto); -// assert(cp->addr); /* these are zero for rendezvous extra-hops */ -// assert(cp->port); + tor_assert(cp->f_crypto); + tor_assert(cp->b_crypto); +// tor_assert(cp->addr); /* these are zero for rendezvous extra-hops */ +// tor_assert(cp->port); switch(cp->state) { case CPATH_STATE_CLOSED: case CPATH_STATE_OPEN: - assert(!cp->handshake_state); + tor_assert(!cp->handshake_state); break; case CPATH_STATE_AWAITING_KEYS: - assert(cp->handshake_state); + tor_assert(cp->handshake_state); break; default: - assert(0); + tor_assert(0); } - assert(cp->package_window >= 0); - assert(cp->deliver_window >= 0); + tor_assert(cp->package_window >= 0); + tor_assert(cp->deliver_window >= 0); } void assert_cpath_ok(const crypt_path_t *cp) @@ -1768,10 +1767,10 @@ void assert_cpath_ok(const crypt_path_t *cp) /* layers must be in sequence of: "open* awaiting? closed*" */ if (cp->prev) { if (cp->prev->state == CPATH_STATE_OPEN) { - assert(cp->state == CPATH_STATE_CLOSED || - cp->state == CPATH_STATE_AWAITING_KEYS); + tor_assert(cp->state == CPATH_STATE_CLOSED || + cp->state == CPATH_STATE_AWAITING_KEYS); } else { - assert(cp->state == CPATH_STATE_CLOSED); + tor_assert(cp->state == CPATH_STATE_CLOSED); } } cp = cp->next; @@ -1782,35 +1781,35 @@ void assert_circuit_ok(const circuit_t *c) { connection_t *conn; - assert(c); - assert(c->magic == CIRCUIT_MAGIC); - assert(c->purpose >= _CIRCUIT_PURPOSE_MIN && - c->purpose <= _CIRCUIT_PURPOSE_MAX); + tor_assert(c); + tor_assert(c->magic == CIRCUIT_MAGIC); + tor_assert(c->purpose >= _CIRCUIT_PURPOSE_MIN && + c->purpose <= _CIRCUIT_PURPOSE_MAX); if (c->n_conn) - assert(c->n_conn->type == CONN_TYPE_OR); + tor_assert(c->n_conn->type == CONN_TYPE_OR); if (c->p_conn) - assert(c->p_conn->type == CONN_TYPE_OR); + tor_assert(c->p_conn->type == CONN_TYPE_OR); for (conn = c->p_streams; conn; conn = conn->next_stream) - assert(conn->type == CONN_TYPE_AP); + tor_assert(conn->type == CONN_TYPE_AP); for (conn = c->n_streams; conn; conn = conn->next_stream) - assert(conn->type == CONN_TYPE_EXIT); + tor_assert(conn->type == CONN_TYPE_EXIT); - assert(c->deliver_window >= 0); - assert(c->package_window >= 0); + tor_assert(c->deliver_window >= 0); + tor_assert(c->package_window >= 0); if (c->state == CIRCUIT_STATE_OPEN) { if (c->cpath) { - assert(CIRCUIT_IS_ORIGIN(c)); - assert(!c->n_crypto); - assert(!c->p_crypto); - assert(!c->n_digest); - assert(!c->p_digest); + tor_assert(CIRCUIT_IS_ORIGIN(c)); + tor_assert(!c->n_crypto); + tor_assert(!c->p_crypto); + tor_assert(!c->n_digest); + tor_assert(!c->p_digest); } else { - assert(!CIRCUIT_IS_ORIGIN(c)); - assert(c->n_crypto); - assert(c->p_crypto); - assert(c->n_digest); - assert(c->p_digest); + tor_assert(!CIRCUIT_IS_ORIGIN(c)); + tor_assert(c->n_crypto); + tor_assert(c->p_crypto); + tor_assert(c->n_digest); + tor_assert(c->p_digest); } } if (c->cpath) { @@ -1818,12 +1817,12 @@ void assert_circuit_ok(const circuit_t *c) } if (c->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED) { if (!c->marked_for_close) { - assert(c->rend_splice); - assert(c->rend_splice->rend_splice == c); + tor_assert(c->rend_splice); + tor_assert(c->rend_splice->rend_splice == c); } - assert(c->rend_splice != c); + tor_assert(c->rend_splice != c); } else { - assert(!c->rend_splice); + tor_assert(!c->rend_splice); } } diff --git a/src/or/config.c b/src/or/config.c index 824e5643cb..7793f8029e 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -25,7 +25,7 @@ static int config_assign(or_options_t *options, struct config_line_t *list); /* open configuration file for reading */ static FILE *config_open(const unsigned char *filename) { - assert(filename); + tor_assert(filename); if (strspn(filename,CONFIG_LEGAL_FILENAME_CHARACTERS) != strlen(filename)) { /* filename has illegal letters */ return NULL; @@ -35,7 +35,7 @@ static FILE *config_open(const unsigned char *filename) { /* close configuration file */ static int config_close(FILE *f) { - assert(f); + tor_assert(f); return fclose(f); } @@ -396,7 +396,7 @@ static int resolve_my_address(or_options_t *options) { log_fn(LOG_WARN,"Could not resolve Address %s. Failing.", options->Address); return -1; } - assert(rent->h_length == 4); + tor_assert(rent->h_length == 4); memcpy(&in.s_addr, rent->h_addr,rent->h_length); } if(!explicit_ip && is_internal_IP(htonl(in.s_addr))) { diff --git a/src/or/connection.c b/src/or/connection.c index 2c427396b8..34db732cfd 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -99,8 +99,8 @@ connection_t *connection_new(int type) { } void connection_free(connection_t *conn) { - assert(conn); - assert(conn->magic == CONNECTION_MAGIC); + tor_assert(conn); + tor_assert(conn->magic == CONNECTION_MAGIC); if(!connection_is_listener(conn)) { buf_free(conn->inbuf); @@ -245,7 +245,7 @@ void connection_expire_held_open(void) * for 15 seconds... */ if (conn->hold_open_until_flushed) { - assert(conn->marked_for_close); + tor_assert(conn->marked_for_close); if (now - conn->timestamp_lastwritten >= 15) { log_fn(LOG_WARN,"Giving up on marked_for_close conn that's been flushing for 15s (fd %d, type %s, state %d).", conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state); @@ -422,9 +422,9 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_ static void listener_close_if_present(int type) { connection_t *conn; - assert(type == CONN_TYPE_OR_LISTENER || - type == CONN_TYPE_AP_LISTENER || - type == CONN_TYPE_DIR_LISTENER); + tor_assert(type == CONN_TYPE_OR_LISTENER || + type == CONN_TYPE_AP_LISTENER || + type == CONN_TYPE_DIR_LISTENER); conn = connection_get_by_type(type); if (conn) { connection_close_immediate(conn); @@ -495,9 +495,9 @@ int connection_bucket_read_limit(connection_t *conn) { /* we just read num_read onto conn. Decrement buckets appropriately. */ void connection_bucket_decrement(connection_t *conn, int num_read) { - global_read_bucket -= num_read; assert(global_read_bucket >= 0); + global_read_bucket -= num_read; tor_assert(global_read_bucket >= 0); if(connection_speaks_cells(conn) && conn->state == OR_CONN_STATE_OPEN) { - conn->receiver_bucket -= num_read; assert(conn->receiver_bucket >= 0); + conn->receiver_bucket -= num_read; tor_assert(conn->receiver_bucket >= 0); } if(global_read_bucket == 0) { log_fn(LOG_DEBUG,"global bucket exhausted. Pausing."); @@ -568,14 +568,14 @@ void connection_bucket_refill(struct timeval *now) { } static int connection_receiver_bucket_should_increase(connection_t *conn) { - assert(conn); + tor_assert(conn); if(!connection_speaks_cells(conn)) return 0; /* edge connections don't use receiver_buckets */ if(conn->state != OR_CONN_STATE_OPEN) return 0; /* only open connections play the rate limiting game */ - assert(conn->bandwidth > 0); + tor_assert(conn->bandwidth > 0); if(conn->receiver_bucket > 9*conn->bandwidth) return 0; @@ -677,7 +677,7 @@ int connection_outbuf_too_full(connection_t *conn) { /* return -1 if you want to break the conn, else return 0 */ int connection_handle_write(connection_t *conn) { - assert(!connection_is_listener(conn)); + tor_assert(!connection_is_listener(conn)); conn->timestamp_lastwritten = time(NULL); @@ -815,7 +815,7 @@ connection_t *connection_twin_get_by_addr_port(uint32_t addr, uint16_t port) { get_connection_array(&carray,&n); for(i=0;iidentity_pkey, router->identity_pkey)) { log(LOG_DEBUG,"connection_twin_get_by_addr_port(): Found twin (%s).",conn->address); @@ -893,7 +893,7 @@ int connection_is_listener(connection_t *conn) { } int connection_state_is_open(connection_t *conn) { - assert(conn); + tor_assert(conn); if(conn->marked_for_close) return 0; @@ -909,8 +909,8 @@ int connection_state_is_open(connection_t *conn) { int connection_send_destroy(uint16_t circ_id, connection_t *conn) { cell_t cell; - assert(conn); - assert(connection_speaks_cells(conn)); + tor_assert(conn); + tor_assert(connection_speaks_cells(conn)); memset(&cell, 0, sizeof(cell_t)); cell.circ_id = circ_id; @@ -922,7 +922,7 @@ int connection_send_destroy(uint16_t circ_id, connection_t *conn) { int connection_process_inbuf(connection_t *conn) { - assert(conn); + tor_assert(conn); switch(conn->type) { case CONN_TYPE_OR: @@ -944,7 +944,7 @@ int connection_process_inbuf(connection_t *conn) { int connection_finished_flushing(connection_t *conn) { - assert(conn); + tor_assert(conn); // log_fn(LOG_DEBUG,"entered. Socket %u.", conn->s); @@ -968,17 +968,17 @@ int connection_finished_flushing(connection_t *conn) { void assert_connection_ok(connection_t *conn, time_t now) { - assert(conn); - assert(conn->magic == CONNECTION_MAGIC); - assert(conn->type >= _CONN_TYPE_MIN); - assert(conn->type <= _CONN_TYPE_MAX); + tor_assert(conn); + tor_assert(conn->magic == CONNECTION_MAGIC); + tor_assert(conn->type >= _CONN_TYPE_MIN); + tor_assert(conn->type <= _CONN_TYPE_MAX); if(conn->outbuf_flushlen > 0) { - assert(connection_is_writing(conn) || conn->wants_to_write); + tor_assert(connection_is_writing(conn) || conn->wants_to_write); } if(conn->hold_open_until_flushed) - assert(conn->marked_for_close); + tor_assert(conn->marked_for_close); /* XXX check: wants_to_read, wants_to_write, s, poll_index, * marked_for_close. */ @@ -990,62 +990,62 @@ void assert_connection_ok(connection_t *conn, time_t now) } #if 0 /* computers often go back in time; no way to know */ - assert(!now || conn->timestamp_lastread <= now); - assert(!now || conn->timestamp_lastwritten <= now); - assert(conn->timestamp_created <= conn->timestamp_lastread); - assert(conn->timestamp_created <= conn->timestamp_lastwritten); + tor_assert(!now || conn->timestamp_lastread <= now); + tor_assert(!now || conn->timestamp_lastwritten <= now); + tor_assert(conn->timestamp_created <= conn->timestamp_lastread); + tor_assert(conn->timestamp_created <= conn->timestamp_lastwritten); #endif /* XXX Fix this; no longer so.*/ #if 0 if(conn->type != CONN_TYPE_OR && conn->type != CONN_TYPE_DIR) - assert(!conn->pkey); + tor_assert(!conn->pkey); /* pkey is set if we're a dir client, or if we're an OR in state OPEN * connected to another OR. */ #endif if (conn->type != CONN_TYPE_OR) { - assert(!conn->tls); + tor_assert(!conn->tls); } else { if(conn->state == OR_CONN_STATE_OPEN) { - /* assert(conn->bandwidth > 0); */ + /* tor_assert(conn->bandwidth > 0); */ /* the above isn't necessarily true: if we just did a TLS * handshake but we didn't recognize the other peer, or it * gave a bad cert/etc, then we won't have assigned bandwidth, * yet it will be open. -RD */ - assert(conn->receiver_bucket >= 0); + tor_assert(conn->receiver_bucket >= 0); } - assert(conn->addr && conn->port); - assert(conn->address); + tor_assert(conn->addr && conn->port); + tor_assert(conn->address); if (conn->state != OR_CONN_STATE_CONNECTING) - assert(conn->tls); + tor_assert(conn->tls); } if (conn->type != CONN_TYPE_EXIT && conn->type != CONN_TYPE_AP) { - assert(!conn->stream_id); - assert(!conn->next_stream); - assert(!conn->cpath_layer); - assert(!conn->package_window); - assert(!conn->deliver_window); - assert(!conn->done_sending); - assert(!conn->done_receiving); + tor_assert(!conn->stream_id); + tor_assert(!conn->next_stream); + tor_assert(!conn->cpath_layer); + tor_assert(!conn->package_window); + tor_assert(!conn->deliver_window); + tor_assert(!conn->done_sending); + tor_assert(!conn->done_receiving); } else { /* XXX unchecked: package window, deliver window. */ } if (conn->type == CONN_TYPE_AP) { - assert(conn->socks_request); + tor_assert(conn->socks_request); if (conn->state == AP_CONN_STATE_OPEN) { - assert(conn->socks_request->has_finished); - assert(conn->cpath_layer); + tor_assert(conn->socks_request->has_finished); + tor_assert(conn->cpath_layer); assert_cpath_layer_ok(conn->cpath_layer); } } else { - assert(!conn->socks_request); + tor_assert(!conn->socks_request); } if(conn->type != CONN_TYPE_DIR) { - assert(!conn->purpose); /* only used for dir types currently */ + tor_assert(!conn->purpose); /* only used for dir types currently */ } switch(conn->type) @@ -1053,37 +1053,37 @@ void assert_connection_ok(connection_t *conn, time_t now) case CONN_TYPE_OR_LISTENER: case CONN_TYPE_AP_LISTENER: case CONN_TYPE_DIR_LISTENER: - assert(conn->state == LISTENER_STATE_READY); + tor_assert(conn->state == LISTENER_STATE_READY); break; case CONN_TYPE_OR: - assert(conn->state >= _OR_CONN_STATE_MIN && - conn->state <= _OR_CONN_STATE_MAX); + tor_assert(conn->state >= _OR_CONN_STATE_MIN && + conn->state <= _OR_CONN_STATE_MAX); break; case CONN_TYPE_EXIT: - assert(conn->state >= _EXIT_CONN_STATE_MIN && - conn->state <= _EXIT_CONN_STATE_MAX); + tor_assert(conn->state >= _EXIT_CONN_STATE_MIN && + conn->state <= _EXIT_CONN_STATE_MAX); break; case CONN_TYPE_AP: - assert(conn->state >= _AP_CONN_STATE_MIN && - conn->state <= _AP_CONN_STATE_MAX); - assert(conn->socks_request); + tor_assert(conn->state >= _AP_CONN_STATE_MIN && + conn->state <= _AP_CONN_STATE_MAX); + tor_assert(conn->socks_request); break; case CONN_TYPE_DIR: - assert(conn->state >= _DIR_CONN_STATE_MIN && - conn->state <= _DIR_CONN_STATE_MAX); - assert(conn->purpose >= _DIR_PURPOSE_MIN && - conn->purpose <= _DIR_PURPOSE_MAX); + tor_assert(conn->state >= _DIR_CONN_STATE_MIN && + conn->state <= _DIR_CONN_STATE_MAX); + tor_assert(conn->purpose >= _DIR_PURPOSE_MIN && + conn->purpose <= _DIR_PURPOSE_MAX); break; case CONN_TYPE_DNSWORKER: - assert(conn->state == DNSWORKER_STATE_IDLE || - conn->state == DNSWORKER_STATE_BUSY); + tor_assert(conn->state == DNSWORKER_STATE_IDLE || + conn->state == DNSWORKER_STATE_BUSY); break; case CONN_TYPE_CPUWORKER: - assert(conn->state >= _CPUWORKER_STATE_MIN && - conn->state <= _CPUWORKER_STATE_MAX); + tor_assert(conn->state >= _CPUWORKER_STATE_MIN && + conn->state <= _CPUWORKER_STATE_MAX); break; default: - assert(0); + tor_assert(0); } } diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 4f582890fb..4d67b4ea71 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -40,8 +40,8 @@ void relay_header_unpack(relay_header_t *dest, const char *src) { */ int connection_edge_process_inbuf(connection_t *conn) { - assert(conn); - assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT); + tor_assert(conn); + tor_assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT); if(conn->inbuf_reached_eof) { #ifdef HALF_OPEN @@ -99,7 +99,7 @@ int connection_edge_process_inbuf(connection_t *conn) { } int connection_edge_destroy(uint16_t circ_id, connection_t *conn) { - assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT); + tor_assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT); if(conn->marked_for_close) return 0; /* already marked; probably got an 'end' */ @@ -129,7 +129,7 @@ static char *connection_edge_end_reason(char *payload, uint16_t length) { case END_STREAM_REASON_DONE: return "closed normally"; case END_STREAM_REASON_TIMEOUT: return "gave up (timeout)"; } - assert(0); + tor_assert(0); return ""; } @@ -182,7 +182,7 @@ int connection_edge_send_command(connection_t *fromconn, circuit_t *circ, if(!circ) { log_fn(LOG_WARN,"no circ. Closing conn."); - assert(fromconn); + tor_assert(fromconn); connection_mark_for_close(fromconn, 0); return -1; } @@ -296,7 +296,7 @@ int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, static int num_seen=0; relay_header_t rh; - assert(cell && circ); + tor_assert(cell && circ); relay_header_unpack(&rh, cell->payload); // log_fn(LOG_DEBUG,"command %d stream %d", rh.command, rh.stream_id); @@ -473,8 +473,8 @@ int connection_edge_finished_flushing(connection_t *conn) { unsigned char connected_payload[4]; int e, len=sizeof(e); - assert(conn); - assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT); + tor_assert(conn); + tor_assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT); switch(conn->state) { case EXIT_CONN_STATE_CONNECTING: @@ -509,7 +509,7 @@ int connection_edge_finished_flushing(connection_t *conn) { RELAY_COMMAND_CONNECTED, connected_payload, 4, conn->cpath_layer) < 0) return 0; /* circuit is closed, don't continue */ } - assert(conn->package_window > 0); + tor_assert(conn->package_window > 0); return connection_edge_process_inbuf(conn); /* in case the server has written anything */ case AP_CONN_STATE_OPEN: case EXIT_CONN_STATE_OPEN: @@ -539,8 +539,8 @@ int connection_edge_package_raw_inbuf(connection_t *conn) { char payload[CELL_PAYLOAD_SIZE]; circuit_t *circ; - assert(conn); - assert(!connection_speaks_cells(conn)); + tor_assert(conn); + tor_assert(!connection_speaks_cells(conn)); repeat_connection_edge_package_raw_inbuf: @@ -582,10 +582,10 @@ repeat_connection_edge_package_raw_inbuf: return 0; /* circuit is closed, don't continue */ if(!conn->cpath_layer) { /* non-rendezvous exit */ - assert(circ->package_window > 0); + tor_assert(circ->package_window > 0); circ->package_window--; } else { /* we're an AP, or an exit on a rendezvous circ */ - assert(conn->cpath_layer->package_window > 0); + tor_assert(conn->cpath_layer->package_window > 0); conn->cpath_layer->package_window--; } @@ -628,7 +628,7 @@ void connection_ap_expire_beginning(void) { } continue; } - assert(circ->purpose == CIRCUIT_PURPOSE_C_GENERAL); + tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_GENERAL); if(conn->num_retries >= MAX_STREAM_RETRIES) { log_fn(LOG_WARN,"Stream is %d seconds late. Giving up.", 15*conn->num_retries); @@ -648,7 +648,7 @@ void connection_ap_expire_beginning(void) { /* kludge to make us not try this circuit again, yet to allow * current streams on it to survive if they can: make it * unattractive to use for new streams */ - assert(circ->timestamp_dirty); + tor_assert(circ->timestamp_dirty); circ->timestamp_dirty -= options.NewCircuitPeriod; /* give our stream another 15 seconds to try */ conn->timestamp_lastread += 15; @@ -714,10 +714,10 @@ static int connection_ap_handshake_process_socks(connection_t *conn) { socks_request_t *socks; int sockshere; - assert(conn); - assert(conn->type == CONN_TYPE_AP); - assert(conn->state == AP_CONN_STATE_SOCKS_WAIT); - assert(conn->socks_request); + tor_assert(conn); + tor_assert(conn->type == CONN_TYPE_AP); + tor_assert(conn->state == AP_CONN_STATE_SOCKS_WAIT); + tor_assert(conn->socks_request); socks = conn->socks_request; log_fn(LOG_DEBUG,"entered."); @@ -791,9 +791,9 @@ circuit_get_open_circ_or_launch(connection_t *conn, circuit_t *circ; uint32_t addr; - assert(conn); - assert(circp); - assert(conn->state == AP_CONN_STATE_CIRCUIT_WAIT); + tor_assert(conn); + tor_assert(circp); + tor_assert(conn->state == AP_CONN_STATE_CIRCUIT_WAIT); circ = circuit_get_best(conn, 1, desired_circuit_purpose); @@ -862,8 +862,8 @@ void link_apconn_to_circ(connection_t *apconn, circuit_t *circ) { /* assert_connection_ok(conn, time(NULL)); */ circ->p_streams = apconn; - assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath && circ->cpath->prev); - assert(circ->cpath->prev->state == CPATH_STATE_OPEN); + tor_assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath && circ->cpath->prev); + tor_assert(circ->cpath->prev->state == CPATH_STATE_OPEN); apconn->cpath_layer = circ->cpath->prev; } @@ -878,10 +878,10 @@ int connection_ap_handshake_attach_circuit(connection_t *conn) { int retval; int conn_age; - assert(conn); - assert(conn->type == CONN_TYPE_AP); - assert(conn->state == AP_CONN_STATE_CIRCUIT_WAIT); - assert(conn->socks_request); + tor_assert(conn); + tor_assert(conn->type == CONN_TYPE_AP); + tor_assert(conn->state == AP_CONN_STATE_CIRCUIT_WAIT); + tor_assert(conn->socks_request); conn_age = time(NULL) - conn->timestamp_created; if(conn_age > 60) { @@ -916,13 +916,13 @@ int connection_ap_handshake_attach_circuit(connection_t *conn) { } else { /* we're a rendezvous conn */ circuit_t *rendcirc=NULL, *introcirc=NULL; - assert(!conn->cpath_layer); + tor_assert(!conn->cpath_layer); /* start by finding a rendezvous circuit for us */ retval = circuit_get_open_circ_or_launch(conn, CIRCUIT_PURPOSE_C_REND_JOINED, &rendcirc); if(retval < 0) return -1; /* failed */ - assert(rendcirc); + tor_assert(rendcirc); if(retval > 0) { /* one is already established, attach */ @@ -942,7 +942,7 @@ int connection_ap_handshake_attach_circuit(connection_t *conn) { /* it's on its way. find an intro circ. */ retval = circuit_get_open_circ_or_launch(conn, CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT, &introcirc); if(retval < 0) return -1; /* failed */ - assert(introcirc); + tor_assert(introcirc); if(retval > 0) { /* one has already sent the intro. keep waiting. */ @@ -958,7 +958,7 @@ int connection_ap_handshake_attach_circuit(connection_t *conn) { rendcirc->n_circ_id, introcirc->n_circ_id, conn_age); /* look around for any new intro circs that should introduce */ - assert(introcirc->purpose == CIRCUIT_PURPOSE_C_INTRODUCING); + tor_assert(introcirc->purpose == CIRCUIT_PURPOSE_C_INTRODUCING); if(introcirc->state == CIRCUIT_STATE_OPEN) { log_fn(LOG_INFO,"found open intro circ %d (rend %d); sending introduction. (stream %d sec old)", introcirc->n_circ_id, rendcirc->n_circ_id, conn_age); @@ -1010,9 +1010,9 @@ int connection_ap_handshake_send_begin(connection_t *ap_conn, circuit_t *circ) struct in_addr in; const char *string_addr; - assert(ap_conn->type == CONN_TYPE_AP); - assert(ap_conn->state == AP_CONN_STATE_CIRCUIT_WAIT); - assert(ap_conn->socks_request); + tor_assert(ap_conn->type == CONN_TYPE_AP); + tor_assert(ap_conn->state == AP_CONN_STATE_CIRCUIT_WAIT); + tor_assert(ap_conn->socks_request); ap_conn->stream_id = get_unique_stream_id_by_circ(circ); if (ap_conn->stream_id==0) { @@ -1111,7 +1111,7 @@ void connection_ap_handshake_socks_reply(connection_t *conn, char *reply, connection_write_to_buf(reply, replylen, conn); return; } - assert(conn->socks_request); + tor_assert(conn->socks_request); if(conn->socks_request->socks_version == 4) { memset(buf,0,SOCKS4_NETWORK_LEN); #define SOCKS4_GRANTED 90 @@ -1190,7 +1190,7 @@ static int connection_exit_begin_conn(cell_t *cell, circuit_t *circ) { n_stream->address = tor_strdup("(rendezvous)"); n_stream->state = EXIT_CONN_STATE_CONNECTING; strcpy(n_stream->rend_query, circ->rend_query); - assert(n_stream->rend_query[0]); + tor_assert(n_stream->rend_query[0]); assert_circuit_ok(circ); if(rend_service_set_connection_addr_port(n_stream, circ) < 0) { log_fn(LOG_INFO,"Didn't find rendezvous service (port %d)",n_stream->port); @@ -1271,7 +1271,7 @@ void connection_exit_connect(connection_t *conn) { } int connection_edge_is_rendezvous_stream(connection_t *conn) { - assert(conn); + tor_assert(conn); if(*conn->rend_query) /* XXX */ return 1; return 0; @@ -1281,9 +1281,9 @@ int connection_ap_can_use_exit(connection_t *conn, routerinfo_t *exit) { uint32_t addr; - assert(conn); - assert(conn->type == CONN_TYPE_AP); - assert(conn->socks_request); + tor_assert(conn); + tor_assert(conn->type == CONN_TYPE_AP); + tor_assert(conn->socks_request); log_fn(LOG_DEBUG,"considering nickname %s, for address %s / port %d:", exit->nickname, conn->socks_request->address, @@ -1334,7 +1334,7 @@ static uint32_t client_dns_lookup_entry(const char *address) struct in_addr in; time_t now; - assert(address); + tor_assert(address); if (tor_inet_aton(address, &in)) { log_fn(LOG_DEBUG, "Using static address %s (%08lX)", address, @@ -1374,8 +1374,8 @@ static void client_dns_set_entry(const char *address, uint32_t val) struct in_addr in; time_t now; - assert(address); - assert(val); + tor_assert(address); + tor_assert(val); if (tor_inet_aton(address, &in)) return; diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 3fe3a98652..bb6eb1367e 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -27,7 +27,7 @@ static void cell_unpack(cell_t *dest, const char *src) { int connection_or_process_inbuf(connection_t *conn) { - assert(conn && conn->type == CONN_TYPE_OR); + tor_assert(conn && conn->type == CONN_TYPE_OR); if(conn->inbuf_reached_eof) { log_fn(LOG_INFO,"OR connection reached EOF. Closing."); @@ -43,7 +43,7 @@ int connection_or_process_inbuf(connection_t *conn) { int connection_or_finished_flushing(connection_t *conn) { int e, len=sizeof(e); - assert(conn && conn->type == CONN_TYPE_OR); + tor_assert(conn && conn->type == CONN_TYPE_OR); assert_connection_ok(conn,0); switch(conn->state) { @@ -92,7 +92,7 @@ void connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *route connection_t *connection_or_connect(routerinfo_t *router) { connection_t *conn; - assert(router); + tor_assert(router); if(router_is_me(router)) { log_fn(LOG_WARN,"You asked me to connect to myself! Failing."); @@ -245,8 +245,8 @@ void connection_or_write_cell_to_buf(const cell_t *cell, connection_t *conn) { char networkcell[CELL_NETWORK_SIZE]; char *n = networkcell; - assert(cell && conn); - assert(connection_speaks_cells(conn)); + tor_assert(cell && conn); + tor_assert(connection_speaks_cells(conn)); cell_pack(n, cell); diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c index 09b8c1e72c..8da39515dc 100644 --- a/src/or/cpuworker.c +++ b/src/or/cpuworker.c @@ -27,7 +27,7 @@ void cpu_init(void) { } int connection_cpu_finished_flushing(connection_t *conn) { - assert(conn && conn->type == CONN_TYPE_CPUWORKER); + tor_assert(conn && conn->type == CONN_TYPE_CPUWORKER); connection_stop_writing(conn); return 0; } @@ -70,7 +70,7 @@ int connection_cpu_process_inbuf(connection_t *conn) { connection_t *p_conn; circuit_t *circ; - assert(conn && conn->type == CONN_TYPE_CPUWORKER); + tor_assert(conn && conn->type == CONN_TYPE_CPUWORKER); if(conn->inbuf_reached_eof) { log_fn(LOG_WARN,"Read eof. Worker died unexpectedly."); @@ -90,7 +90,7 @@ int connection_cpu_process_inbuf(connection_t *conn) { if(conn->state == CPUWORKER_STATE_BUSY_ONION) { if(buf_datalen(conn->inbuf) < LEN_ONION_RESPONSE) /* entire answer available? */ return 0; /* not yet */ - assert(buf_datalen(conn->inbuf) == LEN_ONION_RESPONSE); + tor_assert(buf_datalen(conn->inbuf) == LEN_ONION_RESPONSE); connection_fetch_from_buf(&success,1,conn); connection_fetch_from_buf(buf,LEN_ONION_RESPONSE-1,conn); @@ -112,7 +112,7 @@ int connection_cpu_process_inbuf(connection_t *conn) { log_fn(LOG_INFO,"processed onion for a circ that's gone. Dropping."); goto done_processing; } - assert(circ->p_conn); + tor_assert(circ->p_conn); if(onionskin_answer(circ, buf+TAG_LEN, buf+TAG_LEN+ONIONSKIN_REPLY_LEN) < 0) { log_fn(LOG_WARN,"onionskin_answer failed. Closing."); circuit_mark_for_close(circ); @@ -120,7 +120,7 @@ int connection_cpu_process_inbuf(connection_t *conn) { } log_fn(LOG_DEBUG,"onionskin_answer succeeded. Yay."); } else { - assert(0); /* don't ask me to do handshakes yet */ + tor_assert(0); /* don't ask me to do handshakes yet */ } done_processing: @@ -167,7 +167,7 @@ int cpuworker_main(void *data) { log_fn(LOG_INFO,"cpuworker exiting because tor process died."); goto end; } - assert(question_type == CPUWORKER_TASK_ONION); + tor_assert(question_type == CPUWORKER_TASK_ONION); if(read_all(fd, tag, TAG_LEN, 1) != TAG_LEN) { log_fn(LOG_ERR,"read tag failed. Exiting."); @@ -262,7 +262,7 @@ static void spawn_enough_cpuworkers(void) { static void process_pending_task(connection_t *cpuworker) { circuit_t *circ; - assert(cpuworker); + tor_assert(cpuworker); /* for now only process onion tasks */ @@ -284,7 +284,7 @@ int assign_to_cpuworker(connection_t *cpuworker, unsigned char question_type, circuit_t *circ; char tag[TAG_LEN]; - assert(question_type == CPUWORKER_TASK_ONION); + tor_assert(question_type == CPUWORKER_TASK_ONION); if(question_type == CPUWORKER_TASK_ONION) { circ = task; @@ -299,7 +299,7 @@ int assign_to_cpuworker(connection_t *cpuworker, unsigned char question_type, if (!cpuworker) cpuworker = connection_get_by_type_state(CONN_TYPE_CPUWORKER, CPUWORKER_STATE_IDLE); - assert(cpuworker); + tor_assert(cpuworker); if(!circ->p_conn) { log_fn(LOG_INFO,"circ->p_conn gone. Failing circ."); diff --git a/src/or/directory.c b/src/or/directory.c index a8aa296a25..7c3e68a679 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -45,7 +45,7 @@ void directory_initiate_command(routerinfo_t *router, int purpose, conn->port = router->dir_port; conn->address = tor_strdup(router->address); conn->nickname = tor_strdup(router->nickname); - assert(router->identity_pkey); + tor_assert(router->identity_pkey); conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey); conn->purpose = purpose; @@ -101,25 +101,25 @@ static void directory_send_command(connection_t *conn, int purpose, char fetchstring[] = "GET / HTTP/1.0\r\n\r\n"; char tmp[8192]; - assert(conn && conn->type == CONN_TYPE_DIR); + tor_assert(conn && conn->type == CONN_TYPE_DIR); switch(purpose) { case DIR_PURPOSE_FETCH_DIR: - assert(payload == NULL); + tor_assert(payload == NULL); connection_write_to_buf(fetchstring, strlen(fetchstring), conn); break; case DIR_PURPOSE_UPLOAD_DIR: - assert(payload); + tor_assert(payload); snprintf(tmp, sizeof(tmp), "POST / HTTP/1.0\r\nContent-Length: %d\r\n\r\n", payload_len); connection_write_to_buf(tmp, strlen(tmp), conn); connection_write_to_buf(payload, payload_len, conn); break; case DIR_PURPOSE_FETCH_RENDDESC: - assert(payload); + tor_assert(payload); /* this must be true or we wouldn't be doing the lookup */ - assert(payload_len <= REND_SERVICE_ID_LEN); + tor_assert(payload_len <= REND_SERVICE_ID_LEN); memcpy(conn->rend_query, payload, payload_len); conn->rend_query[payload_len] = 0; @@ -127,7 +127,7 @@ static void directory_send_command(connection_t *conn, int purpose, connection_write_to_buf(tmp, strlen(tmp), conn); break; case DIR_PURPOSE_UPLOAD_RENDDESC: - assert(payload); + tor_assert(payload); snprintf(tmp, sizeof(tmp), "POST %s HTTP/1.0\r\nContent-Length: %d\r\n\r\n", rend_publish_string, payload_len); connection_write_to_buf(tmp, strlen(tmp), conn); @@ -167,7 +167,7 @@ int parse_http_url(char *headers, char **url) { */ int parse_http_response(char *headers, int *code, char **message) { int n1, n2; - assert(headers && code); + tor_assert(headers && code); while(isspace((int)*headers)) headers++; /* tolerate leading whitespace */ @@ -190,7 +190,7 @@ int connection_dir_process_inbuf(connection_t *conn) { int body_len=0; int status_code; - assert(conn && conn->type == CONN_TYPE_DIR); + tor_assert(conn && conn->type == CONN_TYPE_DIR); if(conn->inbuf_reached_eof) { if(conn->state != DIR_CONN_STATE_CLIENT_READING) { @@ -443,7 +443,7 @@ static int directory_handle_command(connection_t *conn) { int body_len=0; int r; - assert(conn && conn->type == CONN_TYPE_DIR); + tor_assert(conn && conn->type == CONN_TYPE_DIR); switch(fetch_from_buf_http(conn->inbuf, &headers, MAX_HEADERS_SIZE, @@ -475,7 +475,7 @@ static int directory_handle_command(connection_t *conn) { int connection_dir_finished_flushing(connection_t *conn) { int e, len=sizeof(e); - assert(conn && conn->type == CONN_TYPE_DIR); + tor_assert(conn && conn->type == CONN_TYPE_DIR); switch(conn->state) { case DIR_CONN_STATE_CONNECTING: diff --git a/src/or/dns.c b/src/or/dns.c index cfa3956109..b49e6dafa9 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -150,7 +150,7 @@ int dns_resolve(connection_t *exitconn) { case CACHE_STATE_FAILED: return -1; } - assert(0); + tor_assert(0); } /* not there, need to add it */ resolve = tor_malloc_zero(sizeof(struct cached_resolve)); @@ -182,7 +182,7 @@ static int assign_to_dnsworker(connection_t *exitconn) { connection_t *dnsconn; unsigned char len; - assert(exitconn->state == EXIT_CONN_STATE_RESOLVING); + tor_assert(exitconn->state == EXIT_CONN_STATE_RESOLVING); spawn_enough_dnsworkers(); /* respawn here, to be sure there are enough */ @@ -225,7 +225,7 @@ void connection_dns_remove(connection_t *conn) return; } - assert(resolve->pending_connections); + tor_assert(resolve->pending_connections); assert_connection_ok(conn,0); pend = resolve->pending_connections; @@ -247,7 +247,7 @@ void connection_dns_remove(connection_t *conn) return; /* more are pending */ } } - assert(0); /* not reachable unless onlyconn not in pending list */ + tor_assert(0); /* not reachable unless onlyconn not in pending list */ } } @@ -259,7 +259,7 @@ void assert_connection_edge_not_dns_pending(connection_t *conn) { for(pend = resolve->pending_connections; pend; pend = pend->next) { - assert(pend->conn != conn); + tor_assert(pend->conn != conn); } } } @@ -295,7 +295,7 @@ void dns_cancel_pending_resolve(char *address) { return; } - assert(resolve->pending_connections); + tor_assert(resolve->pending_connections); /* mark all pending connections to fail */ log_fn(LOG_DEBUG, "Failing all connections waiting on DNS resolve of '%s'", @@ -325,7 +325,7 @@ static void dns_purge_resolve(struct cached_resolve *resolve) { } else { /* FFFF make it a doubly linked list if this becomes too slow */ for(tmp=oldest_cached_resolve; tmp && tmp->next != resolve; tmp=tmp->next) ; - assert(tmp); /* it's got to be in the list, or we screwed up somewhere else */ + tor_assert(tmp); /* it's got to be in the list, or we screwed up somewhere else */ tmp->next = resolve->next; /* unlink it */ if(newest_cached_resolve == resolve) @@ -358,14 +358,14 @@ static void dns_found_answer(char *address, uint32_t addr, char outcome) { if (resolve->state != CACHE_STATE_PENDING) { log_fn(LOG_WARN, "Resolved '%s' which was already resolved; ignoring", address); - assert(resolve->pending_connections == NULL); + tor_assert(resolve->pending_connections == NULL); return; } /* Removed this assertion: in fact, we'll sometimes get a double answer * to the same question. This can happen when we ask one worker to resolve * X.Y.Z., then we cancel the request, and then we ask another worker to * resolve X.Y.Z. */ - /* assert(resolve->state == CACHE_STATE_PENDING); */ + /* tor_assert(resolve->state == CACHE_STATE_PENDING); */ resolve->addr = ntohl(addr); if(outcome == DNS_RESOLVE_SUCCEEDED) @@ -402,7 +402,7 @@ static void dns_found_answer(char *address, uint32_t addr, char outcome) { /******************************************************************/ int connection_dns_finished_flushing(connection_t *conn) { - assert(conn && conn->type == CONN_TYPE_DNSWORKER); + tor_assert(conn && conn->type == CONN_TYPE_DNSWORKER); connection_stop_writing(conn); return 0; } @@ -411,7 +411,7 @@ int connection_dns_process_inbuf(connection_t *conn) { char success; uint32_t addr; - assert(conn && conn->type == CONN_TYPE_DNSWORKER); + tor_assert(conn && conn->type == CONN_TYPE_DNSWORKER); if(conn->inbuf_reached_eof) { log_fn(LOG_WARN,"Read eof. Worker died unexpectedly."); @@ -424,10 +424,10 @@ int connection_dns_process_inbuf(connection_t *conn) { return 0; } - assert(conn->state == DNSWORKER_STATE_BUSY); + tor_assert(conn->state == DNSWORKER_STATE_BUSY); if(buf_datalen(conn->inbuf) < 5) /* entire answer available? */ return 0; /* not yet */ - assert(buf_datalen(conn->inbuf) == 5); + tor_assert(buf_datalen(conn->inbuf) == 5); connection_fetch_from_buf(&success,1,conn); connection_fetch_from_buf((char *)&addr,sizeof(uint32_t),conn); @@ -435,8 +435,8 @@ int connection_dns_process_inbuf(connection_t *conn) { log_fn(LOG_DEBUG, "DNSWorker (fd %d) returned answer for '%s'", conn->s, conn->address); - assert(success >= DNS_RESOLVE_FAILED_TRANSIENT); - assert(success <= DNS_RESOLVE_SUCCEEDED); + tor_assert(success >= DNS_RESOLVE_FAILED_TRANSIENT); + tor_assert(success <= DNS_RESOLVE_SUCCEEDED); dns_found_answer(conn->address, addr, success); tor_free(conn->address); @@ -467,7 +467,7 @@ int dnsworker_main(void *data) { log_fn(LOG_INFO,"dnsworker exiting because tor process died."); spawn_exit(); } - assert(address_len > 0); + tor_assert(address_len > 0); if(read_all(fd, address, address_len, 1) != address_len) { log_fn(LOG_ERR,"read hostname failed. Child exiting."); @@ -486,7 +486,7 @@ int dnsworker_main(void *data) { } memset(answer+1,0,4); } else { - assert(rent->h_length == 4); /* break to remind us if we move away from ipv4 */ + tor_assert(rent->h_length == 4); /* break to remind us if we move away from ipv4 */ answer[0] = DNS_RESOLVE_SUCCEEDED; memcpy(answer+1, rent->h_addr, 4); log_fn(LOG_INFO,"Resolved address '%s'.",address); @@ -551,7 +551,7 @@ static void spawn_enough_dnsworkers(void) { */ dnsconn = connection_get_by_type_state_lastwritten(CONN_TYPE_DNSWORKER, DNSWORKER_STATE_BUSY); - assert(dnsconn); + tor_assert(dnsconn); log_fn(LOG_WARN, "%d DNS workers are spawned; all are busy. Killing one.", MAX_DNSWORKERS); @@ -579,7 +579,7 @@ static void spawn_enough_dnsworkers(void) { log_fn(LOG_WARN,"%d of %d dnsworkers are idle. Killing one.", num_dnsworkers-num_dnsworkers_needed, num_dnsworkers); dnsconn = connection_get_by_type_state(CONN_TYPE_DNSWORKER, DNSWORKER_STATE_IDLE); - assert(dnsconn); + tor_assert(dnsconn); connection_mark_for_close(dnsconn,0); num_dnsworkers--; } diff --git a/src/or/main.c b/src/or/main.c index 9416515ca3..9eb470c1eb 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -53,7 +53,7 @@ int has_completed_circuit=0; ****************************************************************************/ int connection_add(connection_t *conn) { - assert(conn); + tor_assert(conn); if(nfds >= options.MaxConn-1) { log_fn(LOG_WARN,"failing because nfds is too high."); @@ -87,8 +87,8 @@ void connection_set_poll_socket(connection_t *conn) { int connection_remove(connection_t *conn) { int current_index; - assert(conn); - assert(nfds>0); + tor_assert(conn); + tor_assert(nfds>0); log_fn(LOG_INFO,"removing socket %d (type %s), nfds now %d", conn->s, CONN_TYPE_TO_STRING(conn->type), nfds-1); @@ -122,7 +122,7 @@ void get_connection_array(connection_t ***array, int *n) { void connection_watch_events(connection_t *conn, short events) { - assert(conn && conn->poll_index < nfds); + tor_assert(conn && conn->poll_index < nfds); poll_array[conn->poll_index].events = events; } @@ -133,7 +133,7 @@ int connection_is_reading(connection_t *conn) { void connection_stop_reading(connection_t *conn) { - assert(conn && conn->poll_index < nfds); + tor_assert(conn && conn->poll_index < nfds); log(LOG_DEBUG,"connection_stop_reading() called."); if(poll_array[conn->poll_index].events & POLLIN) @@ -142,7 +142,7 @@ void connection_stop_reading(connection_t *conn) { void connection_start_reading(connection_t *conn) { - assert(conn && conn->poll_index < nfds); + tor_assert(conn && conn->poll_index < nfds); poll_array[conn->poll_index].events |= POLLIN; } @@ -153,7 +153,7 @@ int connection_is_writing(connection_t *conn) { void connection_stop_writing(connection_t *conn) { - assert(conn && conn->poll_index < nfds); + tor_assert(conn && conn->poll_index < nfds); if(poll_array[conn->poll_index].events & POLLOUT) poll_array[conn->poll_index].events -= POLLOUT; @@ -161,7 +161,7 @@ void connection_stop_writing(connection_t *conn) { void connection_start_writing(connection_t *conn) { - assert(conn && conn->poll_index < nfds); + tor_assert(conn && conn->poll_index < nfds); poll_array[conn->poll_index].events |= POLLOUT; } diff --git a/src/or/onion.c b/src/or/onion.c index ac44c0035f..28afe68ba0 100644 --- a/src/or/onion.c +++ b/src/or/onion.c @@ -17,11 +17,11 @@ static int count_acceptable_routers(smartlist_t *routers); int decide_circ_id_type(char *local_nick, char *remote_nick) { int result; - assert(remote_nick); + tor_assert(remote_nick); if(!local_nick) return CIRC_ID_TYPE_LOWER; result = strcmp(local_nick, remote_nick); - assert(result); + tor_assert(result); if(result < 0) return CIRC_ID_TYPE_LOWER; return CIRC_ID_TYPE_HIGHER; @@ -45,16 +45,16 @@ int onion_pending_add(circuit_t *circ) { tmp->next = NULL; if(!ol_tail) { - assert(!ol_list); - assert(!ol_length); + tor_assert(!ol_list); + tor_assert(!ol_length); ol_list = tmp; ol_tail = tmp; ol_length++; return 0; } - assert(ol_list); - assert(!ol_tail->next); + tor_assert(ol_list); + tor_assert(!ol_tail->next); if(ol_length >= options.MaxOnionsPending) { log_fn(LOG_WARN,"Already have %d onions queued. Closing.", ol_length); @@ -75,9 +75,9 @@ circuit_t *onion_next_task(void) { if(!ol_list) return NULL; /* no onions pending, we're done */ - assert(ol_list->circ); - assert(ol_list->circ->p_conn); /* make sure it's still valid */ - assert(ol_length > 0); + tor_assert(ol_list->circ); + tor_assert(ol_list->circ->p_conn); /* make sure it's still valid */ + tor_assert(ol_length > 0); circ = ol_list->circ; onion_pending_remove(ol_list->circ); return circ; @@ -164,7 +164,7 @@ static int new_route_len(double cw, uint8_t purpose, smartlist_t *routers) { int num_acceptable_routers; int routelen; - assert((cw >= 0) && (cw < 1) && routers); /* valid parameters */ + tor_assert((cw >= 0) && (cw < 1) && routers); /* valid parameters */ #ifdef TOR_PERF routelen = 2; @@ -361,7 +361,7 @@ static routerinfo_t *choose_good_exit_server(uint8_t purpose, routerlist_t *dir) return r; default: log_fn(LOG_WARN,"unhandled purpose %d", purpose); - assert(0); + tor_assert(0); } return NULL; /* never reached */ } @@ -470,8 +470,8 @@ int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state, rout int i; smartlist_t *sl, *excludednodes; - assert(head_ptr); - assert(router_out); + tor_assert(head_ptr); + tor_assert(router_out); if (!*head_ptr) { cur_len = 0; @@ -534,7 +534,7 @@ int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state, rout remove_twins_from_smartlist(sl,router_get_my_routerinfo()); for (i = 0, cpath = *head_ptr; i < cur_len; ++i, cpath=cpath->next) { r = router_get_by_addr_port(cpath->addr, cpath->port); - assert(r); + tor_assert(r); remove_twins_from_smartlist(sl,r); } smartlist_subtract(sl,excludednodes); @@ -600,8 +600,8 @@ onion_skin_create(crypto_pk_env_t *dest_router_key, dhbytes = crypto_dh_get_bytes(dh); pkbytes = crypto_pk_keysize(dest_router_key); - assert(dhbytes == 128); - assert(pkbytes == 128); + tor_assert(dhbytes == 128); + tor_assert(pkbytes == 128); challenge = tor_malloc_zero(DH_KEY_LEN); if (crypto_dh_get_public(dh, challenge, dhbytes)) @@ -738,7 +738,7 @@ onion_skin_client_handshake(crypto_dh_env_t *handshake_state, { int len; char *key_material=NULL; - assert(crypto_dh_get_bytes(handshake_state) == DH_KEY_LEN); + tor_assert(crypto_dh_get_bytes(handshake_state) == DH_KEY_LEN); #ifdef DEBUG_ONION_SKINS printf("Client: server g^y:"); diff --git a/src/or/rendclient.c b/src/or/rendclient.c index 05191523a1..ee9eedcfed 100644 --- a/src/or/rendclient.c +++ b/src/or/rendclient.c @@ -8,8 +8,8 @@ void rend_client_introcirc_is_open(circuit_t *circ) { - assert(circ->purpose == CIRCUIT_PURPOSE_C_INTRODUCING); - assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath); + tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_INTRODUCING); + tor_assert(CIRCUIT_IS_ORIGIN(circ) && circ->cpath); log_fn(LOG_INFO,"introcirc is open"); connection_ap_attach_pending(); @@ -21,7 +21,7 @@ rend_client_introcirc_is_open(circuit_t *circ) int rend_client_send_establish_rendezvous(circuit_t *circ) { - assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND); + tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND); log_fn(LOG_INFO, "Sending an ESTABLISH_RENDEZVOUS cell"); if (crypto_rand(REND_COOKIE_LEN, circ->rend_cookie)<0) { @@ -52,9 +52,9 @@ rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc) { rend_cache_entry_t *entry; crypt_path_t *cpath; - assert(introcirc->purpose == CIRCUIT_PURPOSE_C_INTRODUCING); - assert(rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY); - assert(!rend_cmp_service_ids(introcirc->rend_query, rendcirc->rend_query)); + tor_assert(introcirc->purpose == CIRCUIT_PURPOSE_C_INTRODUCING); + tor_assert(rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY); + tor_assert(!rend_cmp_service_ids(introcirc->rend_query, rendcirc->rend_query)); if(rend_cache_lookup_entry(introcirc->rend_query, &entry) < 1) { log_fn(LOG_WARN,"query '%s' didn't have valid rend desc in cache. Failing.", @@ -102,7 +102,7 @@ rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc) { goto err; } - assert(DIGEST_LEN + r <= RELAY_PAYLOAD_SIZE); /* we overran something */ + tor_assert(DIGEST_LEN + r <= RELAY_PAYLOAD_SIZE); /* we overran something */ payload_len = DIGEST_LEN + r; if (connection_edge_send_command(NULL, introcirc, @@ -128,8 +128,8 @@ err: void rend_client_rendcirc_is_open(circuit_t *circ) { - assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND); - assert(CIRCUIT_IS_ORIGIN(circ)); + tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND); + tor_assert(CIRCUIT_IS_ORIGIN(circ)); log_fn(LOG_INFO,"rendcirc is open"); @@ -157,7 +157,7 @@ rend_client_introduction_acked(circuit_t *circ, return -1; } - assert(circ->build_state->chosen_exit); + tor_assert(circ->build_state->chosen_exit); if (request_len == 0) { /* It's an ACK; the introduction point relayed our introduction request. */ @@ -185,7 +185,7 @@ rend_client_introduction_acked(circuit_t *circ, /* There are introduction points left. re-extend the circuit to * another intro point and try again. */ nickname = rend_client_get_random_intro(circ->rend_query); - assert(nickname); + tor_assert(nickname); log_fn(LOG_INFO,"Got nack for %s from %s, extending to %s.", circ->rend_query, circ->build_state->chosen_exit, nickname); if (!router_get_by_nickname(nickname)) { log_fn(LOG_WARN, "Advertised intro point '%s' for %s is not known. Closing.", @@ -301,9 +301,9 @@ rend_client_receive_rendezvous(circuit_t *circ, const char *request, int request } /* first DH_KEY_LEN bytes are g^y from bob. Finish the dh handshake...*/ - assert(circ->build_state && circ->build_state->pending_final_cpath); + tor_assert(circ->build_state && circ->build_state->pending_final_cpath); hop = circ->build_state->pending_final_cpath; - assert(hop->handshake_state); + tor_assert(hop->handshake_state); if (crypto_dh_compute_secret(hop->handshake_state, request, DH_KEY_LEN, keys, DIGEST_LEN+CPATH_KEY_MATERIAL_LEN)<0) { log_fn(LOG_WARN, "Couldn't complete DH handshake"); diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c index 7ace58775c..7965e0fa43 100644 --- a/src/or/rendcommon.c +++ b/src/or/rendcommon.c @@ -62,7 +62,7 @@ rend_encode_service_descriptor(rend_service_descriptor_t *desc, return -1; } cp += i; - assert(*len_out == (cp-*str_out)); + tor_assert(*len_out == (cp-*str_out)); return 0; } @@ -127,7 +127,7 @@ rend_service_descriptor_t *rend_parse_service_descriptor( int rend_get_service_id(crypto_pk_env_t *pk, char *out) { char buf[DIGEST_LEN]; - assert(pk); + tor_assert(pk); if (crypto_pk_get_digest(pk, buf) < 0) return -1; if (base32_encode(out, REND_SERVICE_ID_LEN+1, buf, 10) < 0) @@ -185,7 +185,7 @@ int rend_valid_service_id(char *query) { int rend_cache_lookup_entry(char *query, rend_cache_entry_t **e) { - assert(rend_cache); + tor_assert(rend_cache); if (!rend_valid_service_id(query)) return -1; *e = strmap_get_lc(rend_cache, query); @@ -222,7 +222,7 @@ int rend_cache_store(char *desc, int desc_len) rend_service_descriptor_t *parsed; char query[REND_SERVICE_ID_LEN+1]; time_t now; - assert(rend_cache); + tor_assert(rend_cache); parsed = rend_parse_service_descriptor(desc,desc_len); if (!parsed) { log_fn(LOG_WARN,"Couldn't parse service descriptor"); @@ -307,7 +307,7 @@ void rend_process_relay_cell(circuit_t *circ, int command, int length, r = rend_client_rendezvous_acked(circ,payload,length); break; default: - assert(0); + tor_assert(0); } } diff --git a/src/or/rendservice.c b/src/or/rendservice.c index a80057c483..fbb710e5b5 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -214,7 +214,7 @@ int rend_config_services(or_options_t *options) } service->intro_prefer_nodes = tor_strdup(line->value); } else { - assert(!strcasecmp(line->key, "HiddenServiceExcludeNodes")); + tor_assert(!strcasecmp(line->key, "HiddenServiceExcludeNodes")); if (service->intro_exclude_nodes) { log_fn(LOG_WARN, "Got multiple HiddenServiceExcludedNodes lines for a single service"); return -1; @@ -435,7 +435,7 @@ rend_service_introduce(circuit_t *circuit, const char *request, int request_len) rp_nickname, serviceid); return -1; } - assert(launched->build_state); + tor_assert(launched->build_state); /* Fill in the circuit's state. */ memcpy(launched->rend_pk_digest, circuit->rend_pk_digest, DIGEST_LEN); @@ -485,7 +485,7 @@ rend_service_relaunch_rendezvous(circuit_t *oldcirc) } oldstate = oldcirc->build_state; newstate = newcirc->build_state; - assert(newstate && oldstate); + tor_assert(newstate && oldstate); newstate->failure_count = oldstate->failure_count+1; newstate->pending_final_cpath = oldstate->pending_final_cpath; oldstate->pending_final_cpath = NULL; @@ -529,12 +529,12 @@ rend_service_intro_is_ready(circuit_t *circuit) char auth[DIGEST_LEN + 9]; char serviceid[REND_SERVICE_ID_LEN+1]; - assert(circuit->purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO); - assert(CIRCUIT_IS_ORIGIN(circuit) && circuit->cpath); + tor_assert(circuit->purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO); + tor_assert(CIRCUIT_IS_ORIGIN(circuit) && circuit->cpath); if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1, circuit->rend_pk_digest,10)) { - assert(0); + tor_assert(0); } service = rend_service_get_by_pk_digest(circuit->rend_pk_digest); @@ -615,16 +615,16 @@ rend_service_rendezvous_is_ready(circuit_t *circuit) char serviceid[REND_SERVICE_ID_LEN+1]; char hexcookie[9]; - assert(circuit->purpose == CIRCUIT_PURPOSE_S_CONNECT_REND); - assert(circuit->cpath); - assert(circuit->build_state); + tor_assert(circuit->purpose == CIRCUIT_PURPOSE_S_CONNECT_REND); + tor_assert(circuit->cpath); + tor_assert(circuit->build_state); hop = circuit->build_state->pending_final_cpath; - assert(hop); + tor_assert(hop); hex_encode(circuit->rend_cookie, 4, hexcookie); if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1, circuit->rend_pk_digest,10)) { - assert(0); + tor_assert(0); } log_fn(LOG_INFO, @@ -692,7 +692,7 @@ find_intro_circuit(routerinfo_t *router, const char *pk_digest) while ((circ = circuit_get_next_by_pk_and_purpose(circ,pk_digest, CIRCUIT_PURPOSE_S_INTRO))) { - assert(circ->cpath); + tor_assert(circ->cpath); if (circ->build_state->chosen_exit && !strcasecmp(circ->build_state->chosen_exit, router->nickname)) { return circ; @@ -702,7 +702,7 @@ find_intro_circuit(routerinfo_t *router, const char *pk_digest) circ = NULL; while ((circ = circuit_get_next_by_pk_and_purpose(circ,pk_digest, CIRCUIT_PURPOSE_S_ESTABLISH_INTRO))) { - assert(circ->cpath); + tor_assert(circ->cpath); if (circ->build_state->chosen_exit && !strcasecmp(circ->build_state->chosen_exit, router->nickname)) { return circ; @@ -764,7 +764,7 @@ void rend_services_introduce(void) { smartlist_clear(intro_routers); service = smartlist_get(rend_service_list, i); - assert(service); + tor_assert(service); changed = 0; /* Find out which introduction points we have in progress for this service. */ @@ -888,7 +888,7 @@ rend_service_set_connection_addr_port(connection_t *conn, circuit_t *circ) rend_service_port_config_t *p; char serviceid[REND_SERVICE_ID_LEN+1]; - assert(circ->purpose == CIRCUIT_PURPOSE_S_REND_JOINED); + tor_assert(circ->purpose == CIRCUIT_PURPOSE_S_REND_JOINED); log_fn(LOG_DEBUG,"beginning to hunt for addr/port"); if (base32_encode(serviceid, REND_SERVICE_ID_LEN+1, circ->rend_pk_digest,10)) { diff --git a/src/or/rephist.c b/src/or/rephist.c index 8b94a56b88..0e3be24c91 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -61,9 +61,9 @@ static link_history_t *get_link_history(const char *from_name, */ static void update_or_history(or_history_t *hist, time_t when) { - assert(hist); + tor_assert(hist); if (hist->up_since) { - assert(!hist->down_since); + tor_assert(!hist->down_since); hist->uptime += (when - hist->up_since); hist->up_since = when; } else if (hist->down_since) { diff --git a/src/or/router.c b/src/or/router.c index 98ef38dfc5..76bd3afb94 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -22,7 +22,7 @@ void set_onion_key(crypto_pk_env_t *k) { } crypto_pk_env_t *get_onion_key(void) { - assert(onionkey); + tor_assert(onionkey); return onionkey; } @@ -39,7 +39,7 @@ void set_identity_key(crypto_pk_env_t *k) { } crypto_pk_env_t *get_identity_key(void) { - assert(identitykey); + tor_assert(identitykey); return identitykey; } @@ -124,7 +124,7 @@ crypto_pk_env_t *init_key_from_file(const char *fname) } return prkey; default: - assert(0); + tor_assert(0); } error: @@ -146,14 +146,14 @@ int init_keys(void) { /* OP's don't need keys. Just initialize the TLS context.*/ if (!options.ORPort) { - assert(!options.DirPort); + tor_assert(!options.DirPort); if (tor_tls_context_new(NULL, 0, NULL, 0)<0) { log_fn(LOG_ERR, "Error creating TLS context for OP."); return -1; } return 0; } - assert(options.DataDirectory); + tor_assert(options.DataDirectory); if (strlen(options.DataDirectory) > (512-128)) { log_fn(LOG_ERR, "DataDirectory is too long."); return -1; @@ -212,7 +212,7 @@ int init_keys(void) { /* 5. Dump fingerprint to 'fingerprint' */ sprintf(keydir,"%s/fingerprint", options.DataDirectory); log_fn(LOG_INFO,"Dumping fingerprint to %s...",keydir); - assert(strlen(options.Nickname) <= MAX_NICKNAME_LEN); + tor_assert(strlen(options.Nickname) <= MAX_NICKNAME_LEN); strcpy(fingerprint, options.Nickname); strcat(fingerprint, " "); if (crypto_pk_get_fingerprint(get_identity_key(), @@ -349,9 +349,9 @@ static void router_add_exit_policy_from_config(routerinfo_t *router) { */ int router_compare_to_my_exit_policy(connection_t *conn) { - assert(desc_routerinfo); - assert(conn->addr); /* make sure it's resolved to something. this - way we can't get a 'maybe' below. */ + tor_assert(desc_routerinfo); + tor_assert(conn->addr); /* make sure it's resolved to something. this + way we can't get a 'maybe' below. */ return router_compare_addr_to_exit_policy(conn->addr, conn->port, desc_routerinfo->exit_policy); @@ -360,7 +360,7 @@ int router_compare_to_my_exit_policy(connection_t *conn) int router_is_me(routerinfo_t *router) { - assert(router); + tor_assert(router); return options.Nickname && !strcasecmp(router->nickname, options.Nickname); } diff --git a/src/or/routerlist.c b/src/or/routerlist.c index e2ab006da6..4b82d911a9 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -196,8 +196,8 @@ void add_nickname_list_to_smartlist(smartlist_t *sl, char *list) { char nick[MAX_NICKNAME_LEN+1]; routerinfo_t *router; - assert(sl); - assert(list); + tor_assert(sl); + tor_assert(list); while(isspace((int)*list) || *list==',') list++; @@ -295,7 +295,7 @@ routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) { int i; routerinfo_t *router; - assert(routerlist); + tor_assert(routerlist); for(i=0;irouters);i++) { router = smartlist_get(routerlist->routers, i); @@ -310,7 +310,7 @@ routerinfo_t *router_get_by_nickname(char *nickname) int i; routerinfo_t *router; - assert(routerlist); + tor_assert(routerlist); for(i=0;irouters);i++) { router = smartlist_get(routerlist->routers, i); @@ -395,6 +395,7 @@ void router_mark_as_down(char *nickname) { /* ------------------------------------------------------------ */ +#if 0 static void dump_onion_keys(int severity) { int i; @@ -408,6 +409,7 @@ static void dump_onion_keys(int severity) log_fn(severity, "%10s: %s", r->nickname, buf); } } +#endif /* Replace the current router list with the one stored in 'routerfile'. */ int router_set_routerlist_from_file(char *routerfile) @@ -529,7 +531,7 @@ router_resolve(routerinfo_t *router) router->address, router->nickname); return -1; } - assert(rent->h_length == 4); + tor_assert(rent->h_length == 4); memcpy(&router->addr, rent->h_addr,rent->h_length); router->addr = ntohl(router->addr); /* get it back into host order */ @@ -743,7 +745,7 @@ router_get_routerlist_from_directory_impl(const char *str, log_fn(LOG_WARN, "Missing published time on directory."); goto err; } - assert(tok->n_args == 1); + tor_assert(tok->n_args == 1); if (parse_time(tok->args[0], &published_on) < 0) { goto err; @@ -853,7 +855,7 @@ router_get_list_from_string_impl(const char **s, routerlist_t **dest, int i; const char *end; - assert(s && *s); + tor_assert(s && *s); routers = smartlist_create(); @@ -1015,7 +1017,7 @@ routerinfo_t *router_get_entry_from_string(const char *s, if (!(tok = find_first_by_keyword(tokens, K_PUBLISHED))) { log_fn(LOG_WARN, "Missing published time"); goto err; } - assert(tok->n_args == 1); + tor_assert(tok->n_args == 1); if (parse_time(tok->args[0], &router->published_on) < 0) goto err; @@ -1152,7 +1154,7 @@ router_add_exit_policy(routerinfo_t *router, directory_token_t *tok) { char *arg, *address, *mask, *port, *endptr; int bits; - assert(tok->tp == K_REJECT || tok->tp == K_ACCEPT); + tor_assert(tok->tp == K_REJECT || tok->tp == K_ACCEPT); if (tok->n_args != 1) return -1; @@ -1253,7 +1255,7 @@ router_add_exit_policy(routerinfo_t *router, directory_token_t *tok) { return 0; policy_read_failed: - assert(newe->string); + tor_assert(newe->string); log_fn(LOG_WARN,"Couldn't parse line '%s'. Dropping", newe->string); tor_free(newe->string); free(newe); @@ -1271,7 +1273,7 @@ static void token_free(directory_token_t *tok) { int i; - assert(tok); + tor_assert(tok); if (tok->args) { for (i = 0; i < tok->n_args; ++i) { tor_free(tok->args[i]); @@ -1360,7 +1362,7 @@ get_next_token(const char **s, where_syntax where) { *s = eat_whitespace_no_nl(next+1); } else { /* The keyword takes no arguments. */ - assert(a_syn == NO_ARGS); + tor_assert(a_syn == NO_ARGS); *s = eat_whitespace_no_nl(next); if (**s != '\n') { RET_ERR("Unexpected arguments"); diff --git a/src/or/test.c b/src/or/test.c index ab0f23275d..c773e86a4d 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -34,7 +34,7 @@ dump_hex(char *s, int len) for(i=0;i=0;--j) { nyb = (((int) d[i]) >> (j*4)) & 0x0f; - assert(0<=nyb && nyb <=15); + tor_assert(0<=nyb && nyb <=15); putchar(TABLE[nyb]); } }