aboutgitcodebugslistschat
path: root/conf.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-09-26 23:22:31 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-09-27 01:28:02 +0200
commitdfc451319034f594037822b3193a30fa5715175f (patch)
tree80be78db7104b2b4d541a9ce1d5f88c1b0e250ad /conf.c
parent2dbed699e78ed3393ac97a64b04581974070afed (diff)
downloadpasst-dfc451319034f594037822b3193a30fa5715175f.tar
passt-dfc451319034f594037822b3193a30fa5715175f.tar.gz
passt-dfc451319034f594037822b3193a30fa5715175f.tar.bz2
passt-dfc451319034f594037822b3193a30fa5715175f.tar.lz
passt-dfc451319034f594037822b3193a30fa5715175f.tar.xz
passt-dfc451319034f594037822b3193a30fa5715175f.tar.zst
passt-dfc451319034f594037822b3193a30fa5715175f.zip
conf: Actually zero-terminate DNS and search list arrays
This worked pretty much by chance until now. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/conf.c b/conf.c
index e956240..f038584 100644
--- a/conf.c
+++ b/conf.c
@@ -546,13 +546,17 @@ static void get_dns(struct ctx *c)
if (end)
*end = 0;
- if (dns4 - &c->dns4[0] < ARRAY_SIZE(c->dns4) &&
- inet_pton(AF_INET, p + 1, dns4))
+ if (dns4 - &c->dns4[0] < ARRAY_SIZE(c->dns4) - 1 &&
+ inet_pton(AF_INET, p + 1, dns4)) {
dns4++;
+ *dns4 = 0;
+ }
- if (dns6 - &c->dns6[0] < ARRAY_SIZE(c->dns6) &&
- inet_pton(AF_INET6, p + 1, dns6))
+ if (dns6 - &c->dns6[0] < ARRAY_SIZE(c->dns6) - 1 &&
+ inet_pton(AF_INET6, p + 1, dns6)) {
dns6++;
+ memset(dns6, 0, sizeof(*dns6));
+ }
} else if (!dnss_set && strstr(buf, "search ") == buf &&
s == c->dns_search) {
end = strpbrk(buf, "\n");
@@ -560,10 +564,11 @@ static void get_dns(struct ctx *c)
*end = 0;
p = strtok(buf, " \t");
- while ((p = strtok(NULL, " \t")) &&
- s - c->dns_search < ARRAY_SIZE(c->dns_search)) {
+ while (s - c->dns_search < ARRAY_SIZE(c->dns_search) - 1
+ && (p = strtok(NULL, " \t"))) {
strncpy(s->n, p, sizeof(c->dns_search[0]));
s++;
+ *s->n = 0;
}
}
}