From 46b9578caddf9fbed587d4bc21ebbd7b1ba7e726 Mon Sep 17 00:00:00 2001 From: thorkill Date: Tue, 30 Jun 2015 02:03:15 +0200 Subject: [PATCH] Still hunting down uninitialized variables --- src/event.c | 7 ++++++- src/protocol_auth.c | 7 ++++--- src/protocol_key.c | 24 ++++++++++++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/event.c b/src/event.c index 1f42c68d..032f1a23 100644 --- a/src/event.c +++ b/src/event.c @@ -259,10 +259,15 @@ bool event_loop(void) { while(running) { struct timeval diff; - struct timeval *tv = get_time_remaining(&diff); + struct timeval *tv = NULL; + + + memset(&diff, 0x0, sizeof diff); memcpy(&readable, &readfds, sizeof readable); memcpy(&writable, &writefds, sizeof writable); + tv = get_time_remaining(&diff); + int fds = 0; if(io_tree.tail) { diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 78c19ba3..6782226b 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -498,10 +498,11 @@ bool metakey_h(connection_t *c, const char *request) { char enckey[len]; char key[len]; - bzero(key, len); - bzero(enckey, len); + memset(&key, 0x0, len); + memset(&enckey, 0x0, len); + memset(&hexkey,0x0, MAX_STRING_SIZE); - cipher = digest = maclength =compression = 0; + cipher = digest = maclength = compression = -1; if(sscanf(request, "%*d %d %d %d %d " MAX_STRING, &cipher, &digest, &maclength, &compression, hexkey) != 5) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "METAKEY", c->name, c->hostname); diff --git a/src/protocol_key.c b/src/protocol_key.c index eb64711d..c0792dd3 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -58,7 +58,7 @@ void send_key_changed(void) { bool key_changed_h(connection_t *c, const char *request) { char name[MAX_STRING_SIZE]; node_t *n; - + memset(&name, 0x0, MAX_STRING_SIZE); if(sscanf(request, "%*d %*x " MAX_STRING, name) != 1) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "KEY_CHANGED", c->name, c->hostname); @@ -136,6 +136,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, no char buf[MAX_STRING_SIZE]; int len; + memset(&buf, 0x0, MAX_STRING_SIZE); if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, buf) != 1 || !(len = b64decode(buf, buf, strlen(buf)))) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s) to %s (%s): %s", "SPTPS_PACKET", from->name, from->hostname, to->name, to->hostname, "invalid SPTPS data"); return true; @@ -190,6 +191,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, no } char pubkey[MAX_STRING_SIZE]; + memset(&pubkey, 0x0, MAX_STRING_SIZE); if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, pubkey) != 1 || !(from->ecdsa = ecdsa_set_base64_public_key(pubkey))) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s): %s", "ANS_PUBKEY", from->name, from->hostname, "invalid pubkey"); return true; @@ -211,7 +213,9 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, no logger(DEBUG_ALWAYS, LOG_DEBUG, "Got REQ_KEY from %s while we already started a SPTPS session!", from->name); char buf[MAX_STRING_SIZE]; - int len; + int len = -1; + + memset(&buf, 0x0, MAX_STRING_SIZE); if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, buf) != 1 || !(len = b64decode(buf, buf, strlen(buf)))) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s): %s", "REQ_SPTPS_START", from->name, from->hostname, "invalid SPTPS data"); @@ -242,6 +246,9 @@ bool req_key_h(connection_t *c, const char *request) { node_t *from, *to; int reqno = 0; + memset(&from_name, 0x0, MAX_STRING_SIZE); + memset(&to_name, 0x0, MAX_STRING_SIZE); + if(sscanf(request, "%*d " MAX_STRING " " MAX_STRING " %d", from_name, to_name, &reqno) < 2) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "REQ_KEY", c->name, c->hostname); @@ -354,11 +361,20 @@ bool ans_key_h(connection_t *c, const char *request) { char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; char key[MAX_STRING_SIZE]; - char address[MAX_STRING_SIZE] = ""; - char port[MAX_STRING_SIZE] = ""; + char address[MAX_STRING_SIZE]; + char port[MAX_STRING_SIZE]; int cipher, digest, maclength, compression, keylen; node_t *from, *to; + from = to = NULL; + + cipher = digest = maclength = compression = keylen = -1; + memset(&from_name, 0x0, MAX_STRING_SIZE); + memset(&to_name, 0x0, MAX_STRING_SIZE); + memset(&key, 0x0, MAX_STRING_SIZE); + memset(&address, 0x0, MAX_STRING_SIZE); + memset(&port, 0x0, MAX_STRING_SIZE); + if(sscanf(request, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d "MAX_STRING" "MAX_STRING, from_name, to_name, key, &cipher, &digest, &maclength, &compression, address, port) < 7) {