From: Wei Liu Subject: Re: [PATCH 2/2] tools/libxl/libxl_qmp.c: Close fds on error path in qmp_open Date: Wed, 18 Mar 2015 10:15:28 +0000 Message-ID: <20150318101528.GF23662@zion.uk.xensource.com> References: <1426661435-23026-1-git-send-email-pramod.devendra@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYB0g-0007Pv-Hg for xen-devel@lists.xenproject.org; Wed, 18 Mar 2015 10:15:34 +0000 Content-Disposition: inline In-Reply-To: <1426661435-23026-1-git-send-email-pramod.devendra@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: PRAMOD DEVENDRA Cc: xen-devel@lists.xenproject.org, Wei Liu , Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org On Wed, Mar 18, 2015 at 06:50:35AM +0000, PRAMOD DEVENDRA wrote: > From: Pramod Devendra > > Signed-off-by: Pramod Devendra > CC: Ian Jackson > CC: Stefano Stabellini > CC: Ian Campbell > CC: Wei Liu Thanks. The patch content looks good. However the patch title and commit message are not descriptive enough. Can you change the title to: libxl/libxl_qmp.c: fix qmp_open And then in commit message: This patch does following things: 1. Make sure sun_path does not overflow. 2. Close qmp_fd on error. For more general information on patch submission, please refer to http://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches Wei. > --- > tools/libxl/libxl_qmp.c | 17 ++++++++++++++--- > 1 file changed, 14 insertions(+), 3 deletions(-) > > diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c > index c7324e6..992c1ee 100644 > --- a/tools/libxl/libxl_qmp.c > +++ b/tools/libxl/libxl_qmp.c > @@ -365,14 +365,24 @@ static int qmp_open(libxl__qmp_handler *qmp, const char *qmp_socket_path, > return -1; > } > ret = libxl_fd_set_nonblock(qmp->ctx, qmp->qmp_fd, 1); > - if (ret) return -1; > + if (ret) { > + close(qmp->qmp_fd); > + return -1; > + } > ret = libxl_fd_set_cloexec(qmp->ctx, qmp->qmp_fd, 1); > - if (ret) return -1; > + if (ret) { > + close(qmp->qmp_fd); > + return -1; > + } > > + if(sizeof (qmp->addr.sun_path) <= strlen(qmp_socket_path)) { > + close(qmp->qmp_fd); > + return -1; > + } > memset(&qmp->addr, 0, sizeof (qmp->addr)); > qmp->addr.sun_family = AF_UNIX; > strncpy(qmp->addr.sun_path, qmp_socket_path, > - sizeof (qmp->addr.sun_path)); > + sizeof (qmp->addr.sun_path)-1); > > do { > ret = connect(qmp->qmp_fd, (struct sockaddr *) &qmp->addr, > @@ -384,6 +394,7 @@ static int qmp_open(libxl__qmp_handler *qmp, const char *qmp_socket_path, > * ECONNREFUSED : Leftover socket hasn't been removed yet */ > continue; > } > + close(qmp->qmp_fd); > return -1; > } while ((++i / 5 <= timeout) && (usleep(200 * 1000) <= 0)); > > -- > 1.7.10.4