From e7d48709ed6c8569286463552f3df36bbdce8824 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 1 Apr 2021 11:12:57 +0200 Subject: [PATCH] resolved: avoid passing unitialized variable The issue was introduced in the refactoring in 775ae35403f8f3c01b7ac13387fe8aac1759993f. We would pass an initialized value to a helper function. We would only *use* it if it was initialized. But the mere passing of an unitialized variable is UB, so let's not do that. This silences a gcc warning. --- src/resolve/resolved-dns-cache.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c index b74141e6415..f73ead872dd 100644 --- a/src/resolve/resolved-dns-cache.c +++ b/src/resolve/resolved-dns-cache.c @@ -938,6 +938,8 @@ static int answer_add_clamp_ttl( if (FLAGS_SET(query_flags, SD_RESOLVED_CLAMP_TTL)) { uint32_t left_ttl; + assert(current > 0); + /* Let's determine how much time is left for this cache entry. Note that we round down, but * clamp this to be 1s at minimum, since we usually want records to remain cached better too * short a time than too long a time, but otoh don't want to return 0 ever, since that has @@ -988,7 +990,7 @@ int dns_cache_lookup( bool nxdomain = false; DnsCacheItem *j, *first, *nsec = NULL; bool have_authenticated = false, have_non_authenticated = false, have_confidential = false, have_non_confidential = false; - usec_t current; + usec_t current = 0; int found_rcode = -1; DnssecResult dnssec_result = -1; int have_dnssec_result = -1; @@ -1014,8 +1016,12 @@ int dns_cache_lookup( goto miss; } - if (FLAGS_SET(query_flags, SD_RESOLVED_CLAMP_TTL)) + if (FLAGS_SET(query_flags, SD_RESOLVED_CLAMP_TTL)) { + /* 'current' is always passed to answer_add_clamp_ttl(), but is only used conditionally. + * We'll do the same assert there to make sure that it was initialized properly. */ current = now(clock_boottime_or_monotonic()); + assert(current > 0); + } LIST_FOREACH(by_key, j, first) { /* If the caller doesn't allow us to answer questions from cache data learned from -- 2.47.3