don't assert multiple things in the same tor_assert()

svn:r2545
This commit is contained in:
Roger Dingledine 2004-10-16 22:28:11 +00:00
parent de65052312
commit 6d873e5743
5 changed files with 126 additions and 50 deletions

View File

@ -325,7 +325,8 @@ static int crypto_pk_read_private_key_from_string(crypto_pk_env_t *env,
{ {
BIO *b; BIO *b;
tor_assert(env && s); tor_assert(env);
tor_assert(s);
/* Create a read-only memory BIO, backed by the nul-terminated string 's' */ /* Create a read-only memory BIO, backed by the nul-terminated string 's' */
b = BIO_new_mem_buf((char*)s, -1); b = BIO_new_mem_buf((char*)s, -1);
@ -381,7 +382,9 @@ int crypto_pk_write_public_key_to_string(crypto_pk_env_t *env, char **dest, size
BUF_MEM *buf; BUF_MEM *buf;
BIO *b; BIO *b;
tor_assert(env && env->key && dest); tor_assert(env);
tor_assert(env->key);
tor_assert(dest);
b = BIO_new(BIO_s_mem()); /* Create a memory BIO */ b = BIO_new(BIO_s_mem()); /* Create a memory BIO */
@ -414,7 +417,8 @@ int crypto_pk_write_public_key_to_string(crypto_pk_env_t *env, char **dest, size
int crypto_pk_read_public_key_from_string(crypto_pk_env_t *env, const char *src, size_t len) { int crypto_pk_read_public_key_from_string(crypto_pk_env_t *env, const char *src, size_t len) {
BIO *b; BIO *b;
tor_assert(env && src); tor_assert(env);
tor_assert(src);
b = BIO_new(BIO_s_mem()); /* Create a memory BIO */ b = BIO_new(BIO_s_mem()); /* Create a memory BIO */
@ -479,7 +483,8 @@ int crypto_pk_DER64_encode_public_key(crypto_pk_env_t *env, char **out)
{ {
int len; int len;
char buf[PK_BYTES*2]; /* Too long, but hey, stacks are big. */ char buf[PK_BYTES*2]; /* Too long, but hey, stacks are big. */
tor_assert(env && out); tor_assert(env);
tor_assert(out);
len = crypto_pk_asn1_encode(env, buf, sizeof(buf)); len = crypto_pk_asn1_encode(env, buf, sizeof(buf));
if (len < 0) { if (len < 0) {
return -1; return -1;
@ -563,7 +568,8 @@ int crypto_pk_cmp_keys(crypto_pk_env_t *a, crypto_pk_env_t *b) {
/** Return the size of the public key modulus in <b>env</b>, in bytes. */ /** Return the size of the public key modulus in <b>env</b>, in bytes. */
int crypto_pk_keysize(crypto_pk_env_t *env) int crypto_pk_keysize(crypto_pk_env_t *env)
{ {
tor_assert(env && env->key); tor_assert(env);
tor_assert(env->key);
return RSA_size(env->key); return RSA_size(env->key);
} }
@ -571,7 +577,8 @@ int crypto_pk_keysize(crypto_pk_env_t *env)
/** Increase the reference count of <b>env</b>, and return it. /** Increase the reference count of <b>env</b>, and return it.
*/ */
crypto_pk_env_t *crypto_pk_dup_key(crypto_pk_env_t *env) { crypto_pk_env_t *crypto_pk_dup_key(crypto_pk_env_t *env) {
tor_assert(env && env->key); tor_assert(env);
tor_assert(env->key);
env->refs++; env->refs++;
return env; return env;
@ -585,7 +592,9 @@ crypto_pk_env_t *crypto_pk_dup_key(crypto_pk_env_t *env) {
int crypto_pk_public_encrypt(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to, int padding) int crypto_pk_public_encrypt(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to, int padding)
{ {
int r; int r;
tor_assert(env && from && to); tor_assert(env);
tor_assert(from);
tor_assert(to);
r = RSA_public_encrypt(fromlen, (unsigned char*)from, to, env->key, r = RSA_public_encrypt(fromlen, (unsigned char*)from, to, env->key,
crypto_get_rsa_padding(padding)); crypto_get_rsa_padding(padding));
@ -604,7 +613,10 @@ int crypto_pk_public_encrypt(crypto_pk_env_t *env, const unsigned char *from, in
int crypto_pk_private_decrypt(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to, int padding, int warnOnFailure) int crypto_pk_private_decrypt(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to, int padding, int warnOnFailure)
{ {
int r; int r;
tor_assert(env && from && to && env->key); tor_assert(env);
tor_assert(from);
tor_assert(to);
tor_assert(env->key);
if (!env->key->p) if (!env->key->p)
/* Not a private key */ /* Not a private key */
return -1; return -1;
@ -627,7 +639,9 @@ int crypto_pk_private_decrypt(crypto_pk_env_t *env, const unsigned char *from, i
int crypto_pk_public_checksig(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to) int crypto_pk_public_checksig(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to)
{ {
int r; int r;
tor_assert(env && from && to); tor_assert(env);
tor_assert(from);
tor_assert(to);
r = RSA_public_decrypt(fromlen, (unsigned char*)from, to, env->key, RSA_PKCS1_PADDING); r = RSA_public_decrypt(fromlen, (unsigned char*)from, to, env->key, RSA_PKCS1_PADDING);
if (r<0) { if (r<0) {
@ -645,7 +659,9 @@ int crypto_pk_public_checksig(crypto_pk_env_t *env, const unsigned char *from, i
int crypto_pk_private_sign(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to) int crypto_pk_private_sign(crypto_pk_env_t *env, const unsigned char *from, int fromlen, unsigned char *to)
{ {
int r; int r;
tor_assert(env && from && to); tor_assert(env);
tor_assert(from);
tor_assert(to);
if (!env->key->p) if (!env->key->p)
/* Not a private key */ /* Not a private key */
return -1; return -1;
@ -669,7 +685,9 @@ int crypto_pk_public_checksig_digest(crypto_pk_env_t *env, const unsigned char *
char buf[PK_BYTES+1]; char buf[PK_BYTES+1];
int r; int r;
tor_assert(env && data && sig); tor_assert(env);
tor_assert(data);
tor_assert(sig);
if (crypto_digest(data,datalen,digest)<0) { if (crypto_digest(data,datalen,digest)<0) {
log_fn(LOG_WARN, "couldn't compute digest"); log_fn(LOG_WARN, "couldn't compute digest");
@ -728,7 +746,9 @@ int crypto_pk_public_hybrid_encrypt(crypto_pk_env_t *env,
crypto_cipher_env_t *cipher = NULL; crypto_cipher_env_t *cipher = NULL;
char buf[PK_BYTES+1]; char buf[PK_BYTES+1];
tor_assert(env && from && to); tor_assert(env);
tor_assert(from);
tor_assert(to);
overhead = crypto_get_rsa_padding_overhead(crypto_get_rsa_padding(padding)); overhead = crypto_get_rsa_padding_overhead(crypto_get_rsa_padding(padding));
pkeylen = crypto_pk_keysize(env); pkeylen = crypto_pk_keysize(env);
@ -964,7 +984,8 @@ int crypto_cipher_generate_key(crypto_cipher_env_t *env)
*/ */
int crypto_cipher_set_key(crypto_cipher_env_t *env, const unsigned char *key) int crypto_cipher_set_key(crypto_cipher_env_t *env, const unsigned char *key)
{ {
tor_assert(env && key); tor_assert(env);
tor_assert(key);
if (!env->key) if (!env->key)
return -1; return -1;
@ -1009,7 +1030,11 @@ int crypto_cipher_decrypt_init_cipher(crypto_cipher_env_t *env)
*/ */
int crypto_cipher_encrypt(crypto_cipher_env_t *env, const unsigned char *from, unsigned int fromlen, unsigned char *to) int crypto_cipher_encrypt(crypto_cipher_env_t *env, const unsigned char *from, unsigned int fromlen, unsigned char *to)
{ {
tor_assert(env && env->cipher && from && fromlen && to); tor_assert(env);
tor_assert(env->cipher);
tor_assert(from);
tor_assert(fromlen);
tor_assert(to);
aes_crypt(env->cipher, from, fromlen, to); aes_crypt(env->cipher, from, fromlen, to);
return 0; return 0;
@ -1021,7 +1046,9 @@ int crypto_cipher_encrypt(crypto_cipher_env_t *env, const unsigned char *from, u
*/ */
int crypto_cipher_decrypt(crypto_cipher_env_t *env, const unsigned char *from, unsigned int fromlen, unsigned char *to) int crypto_cipher_decrypt(crypto_cipher_env_t *env, const unsigned char *from, unsigned int fromlen, unsigned char *to)
{ {
tor_assert(env && from && to); tor_assert(env);
tor_assert(from);
tor_assert(to);
aes_crypt(env->cipher, from, fromlen, to); aes_crypt(env->cipher, from, fromlen, to);
return 0; return 0;
@ -1054,7 +1081,8 @@ crypto_cipher_advance(crypto_cipher_env_t *env, long delta)
*/ */
int crypto_digest(const unsigned char *m, int len, unsigned char *digest) int crypto_digest(const unsigned char *m, int len, unsigned char *digest)
{ {
tor_assert(m && digest); tor_assert(m);
tor_assert(digest);
return (SHA1(m,len,digest) == NULL); return (SHA1(m,len,digest) == NULL);
} }
@ -1105,7 +1133,8 @@ void crypto_digest_get_digest(crypto_digest_env_t *digest,
{ {
static char r[DIGEST_LEN]; static char r[DIGEST_LEN];
SHA_CTX tmpctx; SHA_CTX tmpctx;
tor_assert(digest && out); tor_assert(digest);
tor_assert(out);
tor_assert(out_len <= DIGEST_LEN); tor_assert(out_len <= DIGEST_LEN);
/* memcpy into a temporary ctx, since SHA1_Final clears the context */ /* memcpy into a temporary ctx, since SHA1_Final clears the context */
memcpy(&tmpctx, &digest->d, sizeof(SHA_CTX)); memcpy(&tmpctx, &digest->d, sizeof(SHA_CTX));
@ -1133,7 +1162,8 @@ void
crypto_digest_assign(crypto_digest_env_t *into, crypto_digest_assign(crypto_digest_env_t *into,
const crypto_digest_env_t *from) const crypto_digest_env_t *from)
{ {
tor_assert(into && from); tor_assert(into);
tor_assert(from);
memcpy(into,from,sizeof(crypto_digest_env_t)); memcpy(into,from,sizeof(crypto_digest_env_t));
} }
@ -1154,7 +1184,8 @@ static void init_dh_param() {
p = BN_new(); p = BN_new();
g = BN_new(); g = BN_new();
tor_assert(p && g); tor_assert(p);
tor_assert(g);
#if 0 #if 0
/* This is from draft-ietf-ipsec-ike-modp-groups-05.txt. It's a safe /* This is from draft-ietf-ipsec-ike-modp-groups-05.txt. It's a safe
@ -1325,7 +1356,8 @@ int crypto_dh_compute_secret(crypto_dh_env_t *dh,
*/ */
void crypto_dh_free(crypto_dh_env_t *dh) void crypto_dh_free(crypto_dh_env_t *dh)
{ {
tor_assert(dh && dh->dh); tor_assert(dh);
tor_assert(dh->dh);
DH_free(dh->dh); DH_free(dh->dh);
free(dh); free(dh);
} }

View File

@ -233,7 +233,8 @@ static void delete_log(logfile_t *victim) {
logfiles = victim->next; logfiles = victim->next;
else { else {
for(tmpl = logfiles; tmpl && tmpl->next != victim; tmpl=tmpl->next) ; for(tmpl = logfiles; tmpl && tmpl->next != victim; tmpl=tmpl->next) ;
tor_assert(tmpl && tmpl->next == victim); tor_assert(tmpl);
tor_assert(tmpl->next == victim);
tmpl->next = victim->next; tmpl->next = victim->next;
} }
tor_free(victim->filename); tor_free(victim->filename);

View File

@ -53,7 +53,9 @@ tor_gzip_compress(char **out, size_t *out_len,
size_t out_size; size_t out_size;
off_t offset; off_t offset;
tor_assert(out && out_len && in); tor_assert(out);
tor_assert(out_len);
tor_assert(in);
if (method == GZIP_METHOD && !is_gzip_supported()) { if (method == GZIP_METHOD && !is_gzip_supported()) {
/* Old zlib version don't support gzip in deflateInit2 */ /* Old zlib version don't support gzip in deflateInit2 */
@ -136,7 +138,9 @@ tor_gzip_uncompress(char **out, size_t *out_len,
size_t out_size; size_t out_size;
off_t offset; off_t offset;
tor_assert(out && out_len && in); tor_assert(out);
tor_assert(out_len);
tor_assert(in);
if (method == GZIP_METHOD && !is_gzip_supported()) { if (method == GZIP_METHOD && !is_gzip_supported()) {
/* Old zlib version don't support gzip in inflateInit2 */ /* Old zlib version don't support gzip in inflateInit2 */

View File

@ -191,7 +191,10 @@ tor_tls_create_certificate(crypto_pk_env_t *rsa,
start_time = time(NULL); start_time = time(NULL);
tor_assert(rsa && cname && rsa_sign && cname_sign); tor_assert(rsa);
tor_assert(cname);
tor_assert(rsa_sign);
tor_assert(cname_sign);
if (!(sign_pkey = _crypto_pk_env_get_evp_pkey(rsa_sign,1))) if (!(sign_pkey = _crypto_pk_env_get_evp_pkey(rsa_sign,1)))
goto error; goto error;
if (!(pkey = _crypto_pk_env_get_evp_pkey(rsa,0))) if (!(pkey = _crypto_pk_env_get_evp_pkey(rsa,0)))
@ -432,7 +435,8 @@ int
tor_tls_read(tor_tls *tls, char *cp, size_t len) tor_tls_read(tor_tls *tls, char *cp, size_t len)
{ {
int r, err; int r, err;
tor_assert(tls && tls->ssl); tor_assert(tls);
tor_assert(tls->ssl);
tor_assert(tls->state == TOR_TLS_ST_OPEN); tor_assert(tls->state == TOR_TLS_ST_OPEN);
r = SSL_read(tls->ssl, cp, len); r = SSL_read(tls->ssl, cp, len);
if (r > 0) if (r > 0)
@ -457,7 +461,8 @@ int
tor_tls_write(tor_tls *tls, char *cp, size_t n) tor_tls_write(tor_tls *tls, char *cp, size_t n)
{ {
int r, err; int r, err;
tor_assert(tls && tls->ssl); tor_assert(tls);
tor_assert(tls->ssl);
tor_assert(tls->state == TOR_TLS_ST_OPEN); tor_assert(tls->state == TOR_TLS_ST_OPEN);
if (n == 0) if (n == 0)
return 0; return 0;
@ -489,7 +494,8 @@ int
tor_tls_handshake(tor_tls *tls) tor_tls_handshake(tor_tls *tls)
{ {
int r; int r;
tor_assert(tls && tls->ssl); tor_assert(tls);
tor_assert(tls->ssl);
tor_assert(tls->state == TOR_TLS_ST_HANDSHAKE); tor_assert(tls->state == TOR_TLS_ST_HANDSHAKE);
if (tls->isServer) { if (tls->isServer) {
r = SSL_accept(tls->ssl); r = SSL_accept(tls->ssl);
@ -512,7 +518,8 @@ tor_tls_shutdown(tor_tls *tls)
{ {
int r, err; int r, err;
char buf[128]; char buf[128];
tor_assert(tls && tls->ssl); tor_assert(tls);
tor_assert(tls->ssl);
while (1) { while (1) {
if (tls->state == TOR_TLS_ST_SENTCLOSE) { if (tls->state == TOR_TLS_ST_SENTCLOSE) {

View File

@ -234,7 +234,9 @@ int tor_strpartition(char *dest, size_t dest_len,
char *destp; char *destp;
size_t len_in, len_out, len_ins; size_t len_in, len_out, len_ins;
int is_even, remaining; int is_even, remaining;
tor_assert(s && insert && n > 0); tor_assert(s);
tor_assert(insert);
tor_assert(n > 0);
len_in = strlen(s); len_in = strlen(s);
len_ins = strlen(insert); len_ins = strlen(insert);
len_out = len_in + (len_in/n)*len_ins; len_out = len_in + (len_in/n)*len_ins;
@ -487,7 +489,9 @@ void *smartlist_choose(const smartlist_t *sl) {
*/ */
void *smartlist_get(const smartlist_t *sl, int idx) void *smartlist_get(const smartlist_t *sl, int idx)
{ {
tor_assert(sl && idx>=0 && idx < sl->num_used); tor_assert(sl);
tor_assert(idx>=0);
tor_assert(idx < sl->num_used);
return sl->list[idx]; return sl->list[idx];
} }
/** Change the value of the <b>idx</b>th element of sl to <b>val</b>; return the old /** Change the value of the <b>idx</b>th element of sl to <b>val</b>; return the old
@ -496,7 +500,9 @@ void *smartlist_get(const smartlist_t *sl, int idx)
void *smartlist_set(smartlist_t *sl, int idx, void *val) void *smartlist_set(smartlist_t *sl, int idx, void *val)
{ {
void *old; void *old;
tor_assert(sl && idx>=0 && idx < sl->num_used); tor_assert(sl);
tor_assert(idx>=0);
tor_assert(idx < sl->num_used);
old = sl->list[idx]; old = sl->list[idx];
sl->list[idx] = val; sl->list[idx] = val;
return old; return old;
@ -508,7 +514,9 @@ void *smartlist_set(smartlist_t *sl, int idx, void *val)
void *smartlist_del(smartlist_t *sl, int idx) void *smartlist_del(smartlist_t *sl, int idx)
{ {
void *old; void *old;
tor_assert(sl && idx>=0 && idx < sl->num_used); tor_assert(sl);
tor_assert(idx>=0);
tor_assert(idx < sl->num_used);
old = sl->list[idx]; old = sl->list[idx];
sl->list[idx] = sl->list[--sl->num_used]; sl->list[idx] = sl->list[--sl->num_used];
return old; return old;
@ -520,7 +528,9 @@ void *smartlist_del(smartlist_t *sl, int idx)
void *smartlist_del_keeporder(smartlist_t *sl, int idx) void *smartlist_del_keeporder(smartlist_t *sl, int idx)
{ {
void *old; void *old;
tor_assert(sl && idx>=0 && idx < sl->num_used); tor_assert(sl);
tor_assert(idx>=0);
tor_assert(idx < sl->num_used);
old = sl->list[idx]; old = sl->list[idx];
--sl->num_used; --sl->num_used;
if (idx < sl->num_used) if (idx < sl->num_used)
@ -539,7 +549,9 @@ int smartlist_len(const smartlist_t *sl)
*/ */
void smartlist_insert(smartlist_t *sl, int idx, void *val) void smartlist_insert(smartlist_t *sl, int idx, void *val)
{ {
tor_assert(sl && idx >= 0 && idx <= sl->num_used); tor_assert(sl);
tor_assert(idx>=0);
tor_assert(idx < sl->num_used);
if (idx == sl->num_used) { if (idx == sl->num_used) {
smartlist_add(sl, val); smartlist_add(sl, val);
} else { } else {
@ -572,7 +584,9 @@ int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep,
const char *cp, *end, *next; const char *cp, *end, *next;
int n = 0; int n = 0;
tor_assert(sl && str && sep); tor_assert(sl);
tor_assert(str);
tor_assert(sep);
cp = str; cp = str;
while (1) { while (1) {
@ -620,7 +634,8 @@ char *smartlist_join_strings(smartlist_t *sl, const char *join, int terminate)
size_t n = 0, jlen; size_t n = 0, jlen;
char *r = NULL, *dst, *src; char *r = NULL, *dst, *src;
tor_assert(sl && join); tor_assert(sl);
tor_assert(join);
jlen = strlen(join); jlen = strlen(join);
for (i = 0; i < sl->num_used; ++i) { for (i = 0; i < sl->num_used; ++i) {
n += strlen(sl->list[i]); n += strlen(sl->list[i]);
@ -681,7 +696,9 @@ void* strmap_set(strmap_t *map, const char *key, void *val)
strmap_entry_t *resolve; strmap_entry_t *resolve;
strmap_entry_t search; strmap_entry_t search;
void *oldval; void *oldval;
tor_assert(map && key && val); tor_assert(map);
tor_assert(key);
tor_assert(val);
search.key = (char*)key; search.key = (char*)key;
resolve = SPLAY_FIND(strmap_tree, &map->head, &search); resolve = SPLAY_FIND(strmap_tree, &map->head, &search);
if (resolve) { if (resolve) {
@ -704,7 +721,8 @@ void* strmap_get(strmap_t *map, const char *key)
{ {
strmap_entry_t *resolve; strmap_entry_t *resolve;
strmap_entry_t search; strmap_entry_t search;
tor_assert(map && key); tor_assert(map);
tor_assert(key);
search.key = (char*)key; search.key = (char*)key;
resolve = SPLAY_FIND(strmap_tree, &map->head, &search); resolve = SPLAY_FIND(strmap_tree, &map->head, &search);
if (resolve) { if (resolve) {
@ -725,7 +743,8 @@ void* strmap_remove(strmap_t *map, const char *key)
strmap_entry_t *resolve; strmap_entry_t *resolve;
strmap_entry_t search; strmap_entry_t search;
void *oldval; void *oldval;
tor_assert(map && key); tor_assert(map);
tor_assert(key);
search.key = (char*)key; search.key = (char*)key;
resolve = SPLAY_FIND(strmap_tree, &map->head, &search); resolve = SPLAY_FIND(strmap_tree, &map->head, &search);
if (resolve) { if (resolve) {
@ -804,7 +823,8 @@ void strmap_foreach(strmap_t *map,
void *data) void *data)
{ {
strmap_entry_t *ptr, *next; strmap_entry_t *ptr, *next;
tor_assert(map && fn); tor_assert(map);
tor_assert(fn);
for (ptr = SPLAY_MIN(strmap_tree, &map->head); ptr != NULL; ptr = next) { for (ptr = SPLAY_MIN(strmap_tree, &map->head); ptr != NULL; ptr = next) {
/* This remove-in-place usage is specifically blessed in tree(3). */ /* This remove-in-place usage is specifically blessed in tree(3). */
next = SPLAY_NEXT(strmap_tree, &map->head, ptr); next = SPLAY_NEXT(strmap_tree, &map->head, ptr);
@ -852,7 +872,8 @@ strmap_iter_t *strmap_iter_init(strmap_t *map)
*/ */
strmap_iter_t *strmap_iter_next(strmap_t *map, strmap_iter_t *iter) strmap_iter_t *strmap_iter_next(strmap_t *map, strmap_iter_t *iter)
{ {
tor_assert(map && iter); tor_assert(map);
tor_assert(iter);
return SPLAY_NEXT(strmap_tree, &map->head, iter); return SPLAY_NEXT(strmap_tree, &map->head, iter);
} }
/** Advance the iterator <b>iter</b> a single step to the next entry, removing /** Advance the iterator <b>iter</b> a single step to the next entry, removing
@ -861,7 +882,8 @@ strmap_iter_t *strmap_iter_next(strmap_t *map, strmap_iter_t *iter)
strmap_iter_t *strmap_iter_next_rmv(strmap_t *map, strmap_iter_t *iter) strmap_iter_t *strmap_iter_next_rmv(strmap_t *map, strmap_iter_t *iter)
{ {
strmap_iter_t *next; strmap_iter_t *next;
tor_assert(map && iter); tor_assert(map);
tor_assert(iter);
next = SPLAY_NEXT(strmap_tree, &map->head, iter); next = SPLAY_NEXT(strmap_tree, &map->head, iter);
SPLAY_REMOVE(strmap_tree, &map->head, iter); SPLAY_REMOVE(strmap_tree, &map->head, iter);
tor_free(iter->key); tor_free(iter->key);
@ -872,7 +894,9 @@ strmap_iter_t *strmap_iter_next_rmv(strmap_t *map, strmap_iter_t *iter)
*/ */
void strmap_iter_get(strmap_iter_t *iter, const char **keyp, void **valp) void strmap_iter_get(strmap_iter_t *iter, const char **keyp, void **valp)
{ {
tor_assert(iter && keyp && valp); tor_assert(iter);
tor_assert(keyp);
tor_assert(valp);
*keyp = iter->key; *keyp = iter->key;
*valp = iter->val; *valp = iter->val;
} }
@ -1069,7 +1093,8 @@ time_t tor_timegm (struct tm *tm) {
int i; int i;
year = tm->tm_year + 1900; year = tm->tm_year + 1900;
tor_assert(year >= 1970); tor_assert(year >= 1970);
tor_assert(tm->tm_mon >= 0 && tm->tm_mon <= 11); tor_assert(tm->tm_mon >= 0);
tor_assert(tm->tm_mon <= 11);
days = 365 * (year-1970) + n_leapdays(1970,year); days = 365 * (year-1970) + n_leapdays(1970,year);
for (i = 0; i < tm->tm_mon; ++i) for (i = 0; i < tm->tm_mon; ++i)
days += days_per_month[i]; days += days_per_month[i];
@ -1094,9 +1119,11 @@ void format_rfc1123_time(char *buf, time_t t) {
struct tm *tm = gmtime(&t); struct tm *tm = gmtime(&t);
strftime(buf, RFC1123_TIME_LEN+1, "XXX, %d XXX %Y %H:%M:%S GMT", tm); strftime(buf, RFC1123_TIME_LEN+1, "XXX, %d XXX %Y %H:%M:%S GMT", tm);
tor_assert(tm->tm_wday >= 0 && tm->tm_wday <= 6); tor_assert(tm->tm_wday >= 0);
tor_assert(tm->tm_wday <= 6);
memcpy(buf, WEEKDAY_NAMES[tm->tm_wday], 3); memcpy(buf, WEEKDAY_NAMES[tm->tm_wday], 3);
tor_assert(tm->tm_wday >= 0 && tm->tm_mon <= 11); tor_assert(tm->tm_wday >= 0);
tor_assert(tm->tm_mon <= 11);
memcpy(buf+8, MONTH_NAMES[tm->tm_mon], 3); memcpy(buf+8, MONTH_NAMES[tm->tm_mon], 3);
} }
@ -2010,7 +2037,8 @@ int tor_inet_aton(const char *c, struct in_addr* addr)
return inet_aton(c, addr); return inet_aton(c, addr);
#else #else
uint32_t r; uint32_t r;
tor_assert(c && addr); tor_assert(c);
tor_assert(addr);
if (strcmp(c, "255.255.255.255") == 0) { if (strcmp(c, "255.255.255.255") == 0) {
addr->s_addr = 0xFFFFFFFFu; addr->s_addr = 0xFFFFFFFFu;
return 1; return 1;
@ -2132,7 +2160,11 @@ parse_addr_and_port_range(const char *s, uint32_t *addr_out,
struct in_addr in; struct in_addr in;
int bits; int bits;
tor_assert(s && addr_out && mask_out && port_min_out && port_max_out); tor_assert(s);
tor_assert(addr_out);
tor_assert(mask_out);
tor_assert(port_min_out);
tor_assert(port_max_out);
address = tor_strdup(s); address = tor_strdup(s);
/* Break 'address' into separate strings. /* Break 'address' into separate strings.