interface-ip: fix memory corruption bug when using jail network namespaces
authorJunnan Xu <junnanx.xu@gmail.com>
Tue, 31 May 2022 14:31:19 +0000 (22:31 +0800)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 31 May 2022 14:44:55 +0000 (15:44 +0100)
memory corruption when resolv_conf specified by input -r parameters
and the resolv_conf length less than "/tmp/resolv.conf-.d/resolv.conf.auto"

Signed-off-by: Junnan Xu <junnanx.xu@gmail.com>
interface-ip.c

index 585cb6f1d6736b4c4df8b84f344e15e000e6120d..ab4a5cfc2c18f9a9a1772558088ea51207ae2c5a 100644 (file)
@@ -1566,7 +1566,9 @@ __interface_write_dns_entries(FILE *f, const char *jail)
 void
 interface_write_resolv_conf(const char *jail)
 {
-       size_t plen = (jail ? strlen(jail) + 1 : 0 ) + strlen(resolv_conf) + 1;
+       size_t plen = (jail ? strlen(jail) + 1 : 0 ) +
+           (strlen(resolv_conf) >= strlen(DEFAULT_RESOLV_CONF) ?
+           strlen(resolv_conf) : strlen(DEFAULT_RESOLV_CONF) ) + 1;
        char *path = alloca(plen);
        char *dpath = alloca(plen);
        char *tmppath = alloca(plen + 4);