aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-08-21 14:20:02 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-08-21 12:00:00 +0200
commit6852bd07ccd7d155e018b8a80153bc153f7b00cc (patch)
tree252351726ae239587309956975881db28af15634
parentc67989466865d0a3d0a327d8b0d191686e81d8ba (diff)
downloadpasst-6852bd07ccd7d155e018b8a80153bc153f7b00cc.tar
passt-6852bd07ccd7d155e018b8a80153bc153f7b00cc.tar.gz
passt-6852bd07ccd7d155e018b8a80153bc153f7b00cc.tar.bz2
passt-6852bd07ccd7d155e018b8a80153bc153f7b00cc.tar.lz
passt-6852bd07ccd7d155e018b8a80153bc153f7b00cc.tar.xz
passt-6852bd07ccd7d155e018b8a80153bc153f7b00cc.tar.zst
passt-6852bd07ccd7d155e018b8a80153bc153f7b00cc.zip
conf: More accurately count entries added in get_dns()
get_dns() counts the number of guest DNS servers it adds, and gives an error if it couldn't add any. However, this count ignores the fact that add_dns[46]() may in some cases *not* add an entry. Use the array indices we're already tracking to get an accurate count. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--conf.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/conf.c b/conf.c
index 2a52bc3..d19013c 100644
--- a/conf.c
+++ b/conf.c
@@ -427,7 +427,6 @@ static void get_dns(struct ctx *c)
struct lineread resolvconf;
struct in6_addr dns6_tmp;
struct in_addr dns4_tmp;
- unsigned int added = 0;
ssize_t line_len;
char *line, *end;
const char *p;
@@ -455,16 +454,12 @@ static void get_dns(struct ctx *c)
*end = 0;
if (!dns4_set && dns4_idx < ARRAY_SIZE(c->ip4.dns) - 1
- && inet_pton(AF_INET, p + 1, &dns4_tmp)) {
+ && inet_pton(AF_INET, p + 1, &dns4_tmp))
dns4_idx += add_dns4(c, &dns4_tmp, dns4_idx);
- added++;
- }
if (!dns6_set && dns6_idx < ARRAY_SIZE(c->ip6.dns) - 1
- && inet_pton(AF_INET6, p + 1, &dns6_tmp)) {
+ && inet_pton(AF_INET6, p + 1, &dns6_tmp))
dns6_idx += add_dns6(c, &dns6_tmp, dns6_idx);
- added++;
- }
} else if (!dnss_set && strstr(line, "search ") == line &&
s == c->dns_search) {
end = strpbrk(line, "\n");
@@ -491,7 +486,7 @@ static void get_dns(struct ctx *c)
out:
if (!dns_set) {
- if (!added)
+ if (!(dns4_idx + dns6_idx))
warn("Couldn't get any nameserver address");
if (c->no_dhcp_dns)