From patchwork Fri Aug 10 05:01:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 1303981 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 66B7EDFFEB for ; Fri, 10 Aug 2012 05:02:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751817Ab2HJFBb (ORCPT ); Fri, 10 Aug 2012 01:01:31 -0400 Received: from ozlabs.org ([203.10.76.45]:48038 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751328Ab2HJFBa (ORCPT ); Fri, 10 Aug 2012 01:01:30 -0400 Received: by ozlabs.org (Postfix, from userid 1034) id CEF272C0094; Fri, 10 Aug 2012 15:01:29 +1000 (EST) From: Michael Ellerman To: Cc: , asias.hejun@gmail.com Subject: [PATCH] kvm tools: Fix crash when /etc/resolv.conf doesn't exist Date: Fri, 10 Aug 2012 15:01:23 +1000 Message-Id: <1344574883-13503-1-git-send-email-michael@ellerman.id.au> X-Mailer: git-send-email 1.7.9.5 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 Acked-by: Asias He --- 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; }