diff mbox

kvm tools: Fix crash when /etc/resolv.conf doesn't exist

Message ID 1344574883-13503-1-git-send-email-michael@ellerman.id.au (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Ellerman Aug. 10, 2012, 5:01 a.m. UTC
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.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/net/uip/dhcp.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Asias He Aug. 10, 2012, 11:53 p.m. UTC | #1
On Fri, Aug 10, 2012 at 1:01 PM, Michael Ellerman
<michael@ellerman.id.au> wrote:
> 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.
>
> Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
> ---
>  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 e91a7c7..b17d352 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;
>  }
> --
> 1.7.9.5
>

Acked-by:  Asias He <asias.hejun@gmail.com>
Pekka Enberg Aug. 13, 2012, 7:30 a.m. UTC | #2
I've applied all Michal's patches. Thanks guys!
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c
index e91a7c7..b17d352 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;
 }