mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 07:07:52 +01:00
Fix warnings about passing uninitialized buffers into functions
Most of these buffers were never actually inspected, but it's still bad style.
This commit is contained in:
parent
491b6de168
commit
4ff170d7b1
11 changed files with 32 additions and 14 deletions
|
@ -907,6 +907,8 @@ buf_peek_startswith(const buf_t *buf, const char *cmd)
|
||||||
{
|
{
|
||||||
char tmp[PEEK_BUF_STARTSWITH_MAX];
|
char tmp[PEEK_BUF_STARTSWITH_MAX];
|
||||||
size_t clen = strlen(cmd);
|
size_t clen = strlen(cmd);
|
||||||
|
if (clen == 0)
|
||||||
|
return 1;
|
||||||
if (BUG(clen > sizeof(tmp)))
|
if (BUG(clen > sizeof(tmp)))
|
||||||
return 0;
|
return 0;
|
||||||
if (buf->datalen < clen)
|
if (buf->datalen < clen)
|
||||||
|
|
|
@ -2580,6 +2580,7 @@ tor_inet_pton(int af, const char *src, void *dst)
|
||||||
int gapPos = -1, i, setWords=0;
|
int gapPos = -1, i, setWords=0;
|
||||||
const char *dot = strchr(src, '.');
|
const char *dot = strchr(src, '.');
|
||||||
const char *eow; /* end of words. */
|
const char *eow; /* end of words. */
|
||||||
|
memset(words, 0xf8, sizeof(words));
|
||||||
if (dot == src)
|
if (dot == src)
|
||||||
return 0;
|
return 0;
|
||||||
else if (!dot)
|
else if (!dot)
|
||||||
|
|
|
@ -6072,6 +6072,8 @@ parse_dir_authority_line(const char *line, dirinfo_type_t required_type,
|
||||||
dirinfo_type_t type = 0;
|
dirinfo_type_t type = 0;
|
||||||
double weight = 1.0;
|
double weight = 1.0;
|
||||||
|
|
||||||
|
memset(v3_digest, 0, sizeof(v3_digest));
|
||||||
|
|
||||||
items = smartlist_new();
|
items = smartlist_new();
|
||||||
smartlist_split_string(items, line, NULL,
|
smartlist_split_string(items, line, NULL,
|
||||||
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, -1);
|
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, -1);
|
||||||
|
|
|
@ -3993,14 +3993,15 @@ dirvote_format_all_microdesc_vote_lines(const routerinfo_t *ri, time_t now,
|
||||||
while ((ep = entries)) {
|
while ((ep = entries)) {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
vote_microdesc_hash_t *h;
|
vote_microdesc_hash_t *h;
|
||||||
dirvote_format_microdesc_vote_line(buf, sizeof(buf), ep->md,
|
if (dirvote_format_microdesc_vote_line(buf, sizeof(buf), ep->md,
|
||||||
ep->low, ep->high);
|
ep->low, ep->high) >= 0) {
|
||||||
h = tor_malloc_zero(sizeof(vote_microdesc_hash_t));
|
h = tor_malloc_zero(sizeof(vote_microdesc_hash_t));
|
||||||
h->microdesc_hash_line = tor_strdup(buf);
|
h->microdesc_hash_line = tor_strdup(buf);
|
||||||
h->next = result;
|
h->next = result;
|
||||||
result = h;
|
result = h;
|
||||||
ep->md->last_listed = now;
|
ep->md->last_listed = now;
|
||||||
smartlist_add(microdescriptors_out, ep->md);
|
smartlist_add(microdescriptors_out, ep->md);
|
||||||
|
}
|
||||||
entries = ep->next;
|
entries = ep->next;
|
||||||
tor_free(ep);
|
tor_free(ep);
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,6 +161,7 @@ get_token_arguments(memarea_t *area, directory_token_t *tok,
|
||||||
char *cp = mem;
|
char *cp = mem;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
char *args[MAX_ARGS];
|
char *args[MAX_ARGS];
|
||||||
|
memset(args, 0, sizeof(args));
|
||||||
while (*cp) {
|
while (*cp) {
|
||||||
if (j == MAX_ARGS)
|
if (j == MAX_ARGS)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -200,6 +200,7 @@ bench_onion_ntor_impl(void)
|
||||||
curve25519_public_key_generate(&keypair2.pubkey, &keypair2.seckey);
|
curve25519_public_key_generate(&keypair2.pubkey, &keypair2.seckey);
|
||||||
dimap_add_entry(&keymap, keypair1.pubkey.public_key, &keypair1);
|
dimap_add_entry(&keymap, keypair1.pubkey.public_key, &keypair1);
|
||||||
dimap_add_entry(&keymap, keypair2.pubkey.public_key, &keypair2);
|
dimap_add_entry(&keymap, keypair2.pubkey.public_key, &keypair2);
|
||||||
|
crypto_rand((char *)nodeid, sizeof(nodeid));
|
||||||
|
|
||||||
reset_perftime();
|
reset_perftime();
|
||||||
start = perftime();
|
start = perftime();
|
||||||
|
|
|
@ -2595,6 +2595,8 @@ test_crypto_ed25519_testvectors(void *arg)
|
||||||
ed25519_signature_t sig;
|
ed25519_signature_t sig;
|
||||||
int sign;
|
int sign;
|
||||||
|
|
||||||
|
memset(&curvekp, 0xd0, sizeof(curvekp));
|
||||||
|
|
||||||
#define DECODE(p,s) base16_decode((char*)(p),sizeof(p),(s),strlen(s))
|
#define DECODE(p,s) base16_decode((char*)(p),sizeof(p),(s),strlen(s))
|
||||||
#define EQ(a,h) test_memeq_hex((const char*)(a), (h))
|
#define EQ(a,h) test_memeq_hex((const char*)(a), (h))
|
||||||
|
|
||||||
|
|
|
@ -3370,7 +3370,7 @@ mock_get_options(void)
|
||||||
static void
|
static void
|
||||||
reset_routerstatus(routerstatus_t *rs,
|
reset_routerstatus(routerstatus_t *rs,
|
||||||
const char *hex_identity_digest,
|
const char *hex_identity_digest,
|
||||||
int32_t ipv4_addr)
|
uint32_t ipv4_addr)
|
||||||
{
|
{
|
||||||
memset(rs, 0, sizeof(routerstatus_t));
|
memset(rs, 0, sizeof(routerstatus_t));
|
||||||
base16_decode(rs->identity_digest, sizeof(rs->identity_digest),
|
base16_decode(rs->identity_digest, sizeof(rs->identity_digest),
|
||||||
|
|
|
@ -783,7 +783,7 @@ static void
|
||||||
test_received_introduce1_handling(void *arg)
|
test_received_introduce1_handling(void *arg)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
uint8_t *request = NULL, buf[128];
|
uint8_t *request = NULL, buf[128];;
|
||||||
trn_cell_introduce1_t *cell = NULL;
|
trn_cell_introduce1_t *cell = NULL;
|
||||||
or_circuit_t *circ = NULL;
|
or_circuit_t *circ = NULL;
|
||||||
|
|
||||||
|
@ -796,6 +796,7 @@ test_received_introduce1_handling(void *arg)
|
||||||
/* Too small request length. An INTRODUCE1 expect at the very least a
|
/* Too small request length. An INTRODUCE1 expect at the very least a
|
||||||
* DIGEST_LEN size. */
|
* DIGEST_LEN size. */
|
||||||
{
|
{
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
circ = helper_create_intro_circuit();
|
circ = helper_create_intro_circuit();
|
||||||
ret = hs_intro_received_introduce1(circ, buf, DIGEST_LEN - 1);
|
ret = hs_intro_received_introduce1(circ, buf, DIGEST_LEN - 1);
|
||||||
tt_int_op(ret, OP_EQ, -1);
|
tt_int_op(ret, OP_EQ, -1);
|
||||||
|
@ -809,6 +810,7 @@ test_received_introduce1_handling(void *arg)
|
||||||
{
|
{
|
||||||
circ = helper_create_intro_circuit();
|
circ = helper_create_intro_circuit();
|
||||||
uint8_t test[2]; /* Too small request. */
|
uint8_t test[2]; /* Too small request. */
|
||||||
|
memset(test, 0, sizeof(test));
|
||||||
ret = handle_introduce1(circ, test, sizeof(test));
|
ret = handle_introduce1(circ, test, sizeof(test));
|
||||||
tor_free(circ->p_chan);
|
tor_free(circ->p_chan);
|
||||||
circuit_free(TO_CIRCUIT(circ));
|
circuit_free(TO_CIRCUIT(circ));
|
||||||
|
|
|
@ -1231,6 +1231,8 @@ test_keep_commit(void *arg)
|
||||||
state = get_sr_state();
|
state = get_sr_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
crypto_rand((char*)fp, sizeof(fp));
|
||||||
|
|
||||||
/* Test this very important function that tells us if we should keep a
|
/* Test this very important function that tells us if we should keep a
|
||||||
* commit or not in our state. Most of it depends on the phase and what's
|
* commit or not in our state. Most of it depends on the phase and what's
|
||||||
* in the commit so we'll change the commit as we go. */
|
* in the commit so we'll change the commit as we go. */
|
||||||
|
|
|
@ -430,7 +430,7 @@ key_to_string(EVP_PKEY *key)
|
||||||
static int
|
static int
|
||||||
get_fingerprint(EVP_PKEY *pkey, char *out)
|
get_fingerprint(EVP_PKEY *pkey, char *out)
|
||||||
{
|
{
|
||||||
int r = 1;
|
int r = -1;
|
||||||
crypto_pk_t *pk = crypto_new_pk_from_rsa_(EVP_PKEY_get1_RSA(pkey));
|
crypto_pk_t *pk = crypto_new_pk_from_rsa_(EVP_PKEY_get1_RSA(pkey));
|
||||||
if (pk) {
|
if (pk) {
|
||||||
r = crypto_pk_get_fingerprint(pk, out, 0);
|
r = crypto_pk_get_fingerprint(pk, out, 0);
|
||||||
|
@ -443,7 +443,7 @@ get_fingerprint(EVP_PKEY *pkey, char *out)
|
||||||
static int
|
static int
|
||||||
get_digest(EVP_PKEY *pkey, char *out)
|
get_digest(EVP_PKEY *pkey, char *out)
|
||||||
{
|
{
|
||||||
int r = 1;
|
int r = -1;
|
||||||
crypto_pk_t *pk = crypto_new_pk_from_rsa_(EVP_PKEY_get1_RSA(pkey));
|
crypto_pk_t *pk = crypto_new_pk_from_rsa_(EVP_PKEY_get1_RSA(pkey));
|
||||||
if (pk) {
|
if (pk) {
|
||||||
r = crypto_pk_get_digest(pk, out);
|
r = crypto_pk_get_digest(pk, out);
|
||||||
|
@ -472,8 +472,12 @@ generate_certificate(void)
|
||||||
char signature[1024]; /* handles up to 8192-bit keys. */
|
char signature[1024]; /* handles up to 8192-bit keys. */
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
get_fingerprint(identity_key, fingerprint);
|
if (get_fingerprint(identity_key, fingerprint) < 0) {
|
||||||
get_digest(identity_key, id_digest);
|
return -1;
|
||||||
|
}
|
||||||
|
if (get_digest(identity_key, id_digest)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
tor_localtime_r(&now, &tm);
|
tor_localtime_r(&now, &tm);
|
||||||
tm.tm_mon += months_lifetime;
|
tm.tm_mon += months_lifetime;
|
||||||
|
|
Loading…
Add table
Reference in a new issue