From 70abd843fd006cd25dadd388e5f4ff753c3a4668 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Tue, 27 Oct 2009 04:31:23 +0100 Subject: [PATCH 1/3] crypto_cipher_set_key cannot fail In 5e4d53d535a3cc9903250b3df0caa829f1c5e4bf we made it so that crypto_cipher_set_key cannot fail. The call will now always succeed, to returning a boolean for success/failure makes no sense. --- src/common/crypto.c | 9 ++------- src/common/crypto.h | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/common/crypto.c b/src/common/crypto.c index 4c880f6b6f..bc1eb38121 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -426,10 +426,7 @@ crypto_create_init_cipher(const char *key, int encrypt_mode) return NULL; } - if (crypto_cipher_set_key(crypto, key)) { - crypto_log_errors(LOG_WARN, "setting symmetric key"); - goto error; - } + crypto_cipher_set_key(crypto, key); if (encrypt_mode) r = crypto_cipher_encrypt_init_cipher(crypto); @@ -1252,16 +1249,14 @@ crypto_cipher_generate_key(crypto_cipher_env_t *env) /** Set the symmetric key for the cipher in env to the first * CIPHER_KEY_LEN bytes of key. Does not initialize the cipher. - * Return 0 on success, -1 on failure. */ -int +void crypto_cipher_set_key(crypto_cipher_env_t *env, const char *key) { tor_assert(env); tor_assert(key); memcpy(env->key, key, CIPHER_KEY_LEN); - return 0; } /** Generate an initialization vector for our AES-CTR cipher; store it diff --git a/src/common/crypto.h b/src/common/crypto.h index d9adb16f80..239acb5871 100644 --- a/src/common/crypto.h +++ b/src/common/crypto.h @@ -151,7 +151,7 @@ int crypto_pk_check_fingerprint_syntax(const char *s); /* symmetric crypto */ int crypto_cipher_generate_key(crypto_cipher_env_t *env); -int crypto_cipher_set_key(crypto_cipher_env_t *env, const char *key); +void crypto_cipher_set_key(crypto_cipher_env_t *env, const char *key); void crypto_cipher_generate_iv(char *iv_out); int crypto_cipher_set_iv(crypto_cipher_env_t *env, const char *iv); const char *crypto_cipher_get_key(crypto_cipher_env_t *env); From b0e8c33617edec7ec58ce36542cf7d8a4514d89e Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Tue, 27 Oct 2009 14:14:52 +0100 Subject: [PATCH 2/3] Make it more obvious for coverity that cid 404 is not dead code --- src/or/directory.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/or/directory.c b/src/or/directory.c index e703bd438a..0a090e6f16 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -1463,21 +1463,22 @@ connection_dir_client_reached_eof(dir_connection_t *conn) } (void) skewed; /* skewed isn't used yet. */ - if (status_code == 503 && body_len < 16) { - routerstatus_t *rs; - trusted_dir_server_t *ds; - log_info(LD_DIR,"Received http status code %d (%s) from server " - "'%s:%d'. I'll try again soon.", - status_code, escaped(reason), conn->_base.address, - conn->_base.port); - if ((rs = router_get_consensus_status_by_id(conn->identity_digest))) - rs->last_dir_503_at = now; - if ((ds = router_get_trusteddirserver_by_digest(conn->identity_digest))) - ds->fake_status.last_dir_503_at = now; + if (status_code == 503) { + if (body_len < 16) { + routerstatus_t *rs; + trusted_dir_server_t *ds; + log_info(LD_DIR,"Received http status code %d (%s) from server " + "'%s:%d'. I'll try again soon.", + status_code, escaped(reason), conn->_base.address, + conn->_base.port); + if ((rs = router_get_consensus_status_by_id(conn->identity_digest))) + rs->last_dir_503_at = now; + if ((ds = router_get_trusteddirserver_by_digest(conn->identity_digest))) + ds->fake_status.last_dir_503_at = now; - tor_free(body); tor_free(headers); tor_free(reason); - return -1; - } else if (status_code == 503) { + tor_free(body); tor_free(headers); tor_free(reason); + return -1; + } /* XXXX022 Remove this once every server with bug 539 is obsolete. */ log_info(LD_DIR, "Server at '%s:%d' sent us a 503 response, but included " "a body anyway. We'll pretend it gave us a 200.", From f1b7295b27ba1f472304f2931bb23df6884b64e6 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Tue, 27 Oct 2009 17:50:24 +0100 Subject: [PATCH 3/3] Disallow command line keywords with more than two dashes as prefix. This might help fix cid 422, where coverity fails to notice that argv strings are null-escaped. --- src/or/config.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/or/config.c b/src/or/config.c index 5a0ced29d5..1b415ee7a2 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -1563,7 +1563,10 @@ config_get_commandlines(int argc, char **argv, config_line_t **result) *new = tor_malloc_zero(sizeof(config_line_t)); s = argv[i]; - while (*s == '-') + /* Each keyword may be prefixed with one or two dashes. */ + if (*s == '-') + s++; + if (*s == '-') s++; (*new)->key = tor_strdup(expand_abbrev(&options_format, s, 1, 1));