From 183d56fd4087132717e171beeecccb402501e2d1 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 7 Oct 2009 15:11:09 +0200 Subject: [PATCH] Don't use uninitialized values This fixes a bunch or valgrind errors. --- client.c | 2 ++ ntp_core.c | 2 ++ ntp_io.c | 5 +++-- sourcestats.c | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/client.c b/client.c index a8c4ad2..bd250fe 100644 --- a/client.c +++ b/client.c @@ -1158,6 +1158,8 @@ submit_request(CMD_Request *request, CMD_Reply *reply, int *reply_auth_ok) request->utoken = htonl(SPECIAL_UTOKEN); } generate_auth(request); + } else { + memset(request->auth, 0, sizeof (request->auth)); } command_length = PKL_CommandLength(request); diff --git a/ntp_core.c b/ntp_core.c index fcbe046..4f0eb41 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -323,6 +323,8 @@ create_instance(NTP_Remote_Address *remote_addr, NTP_Mode mode, SourceParameters result->local_rx.tv_sec = 0; result->local_rx.tv_usec = 0; + result->local_tx.tv_sec = 0; + result->local_tx.tv_usec = 0; return result; diff --git a/ntp_io.c b/ntp_io.c index 4e4b989..d673105 100644 --- a/ntp_io.c +++ b/ntp_io.c @@ -307,13 +307,14 @@ send_packet(void *packet, int packetlen, NTP_Remote_Address *remote_addr) struct in_pktinfo *ipi; cmsg = CMSG_FIRSTHDR(&msg); + memset(cmsg, 0, CMSG_SPACE(sizeof(struct in_pktinfo))); + cmsglen += CMSG_SPACE(sizeof(struct in_pktinfo)); + cmsg->cmsg_level = IPPROTO_IP; cmsg->cmsg_type = IP_PKTINFO; cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo)); - cmsglen += CMSG_SPACE(sizeof(struct in_pktinfo)); ipi = (struct in_pktinfo *) CMSG_DATA(cmsg); - memset(ipi, 0, sizeof(struct in_pktinfo)); ipi->ipi_spec_dst.s_addr = htonl(remote_addr->local_ip_addr); #if 0 LOG(LOGS_INFO, LOGF_NtpIO, "sending to %s:%d from %s", diff --git a/sourcestats.c b/sourcestats.c index 564eb3a..33c1a1b 100644 --- a/sourcestats.c +++ b/sourcestats.c @@ -198,6 +198,8 @@ SST_CreateInstance(unsigned long refid) inst->skew_dirn = SST_Skew_Nochange; inst->estimated_offset = 0.0; inst->estimated_offset_sd = 86400.0; /* Assume it's at least within a day! */ + inst->offset_time.tv_sec = 0; + inst->offset_time.tv_usec = 0; inst->variance = 16.0; inst->nruns = 0; return inst; @@ -874,6 +876,7 @@ SST_DoSourceReport(SST_Stats inst, RPT_SourceReport *report, struct timeval *now report->resid_skew = 0; } } else { + report->latest_meas_ago = 86400 * 365 * 10; report->orig_latest_meas = 0; report->latest_meas = 0; report->latest_meas_err = 0;