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 <asias.hejun@gmail.com>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
Michael Ellerman
2015-06-01 16:39:52 +01:00
committed by Will Deacon
parent 3258566626
commit a7b946b905
+1 -2
View File
@@ -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;
}