From a2a7af4c58f76b5e724f850a9b4b70f49bc5086c Mon Sep 17 00:00:00 2001 From: Michael Ellerman Date: Fri, 10 Aug 2012 15:01:23 +1000 Subject: [PATCH] kvm tools: Fix crash when /etc/resolv.conf doesn't exist In uip_dhcp_get_dns() we try to open /etc/resolv.conf. If we fail to open it we then SEGV trying to fclose() it. Fix the code to just return directly if we can't open it. Acked-by: Asias He Signed-off-by: Michael Ellerman Signed-off-by: Pekka Enberg --- tools/kvm/net/uip/dhcp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c index e91a7c7a6aca..b17d35239321 100644 --- a/tools/kvm/net/uip/dhcp.c +++ b/tools/kvm/net/uip/dhcp.c @@ -45,7 +45,7 @@ int uip_dhcp_get_dns(struct uip_info *info) fp = fopen("/etc/resolv.conf", "r"); if (!fp) - goto out; + return ret; while (!feof(fp)) { if (fscanf(fp, "%s %s\n", key, val) != 2) @@ -62,7 +62,6 @@ int uip_dhcp_get_dns(struct uip_info *info) } } -out: fclose(fp); return ret; } -- 2.39.5