From 39ef9fe1388029c476db62889ef2ef5661613321 Mon Sep 17 00:00:00 2001 From: Junnan Xu Date: Tue, 31 May 2022 22:31:19 +0800 Subject: interface-ip: fix memory corruption bug when using jail network namespaces 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 --- interface-ip.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'interface-ip.c') diff --git a/interface-ip.c b/interface-ip.c index 585cb6f..ab4a5cf 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -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); -- cgit v1.2.1