From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Campbell Subject: Re: [PATCH for-4.5 1/3] python/xc: Fix multiple issues in pyflask_context_to_sid() Date: Fri, 28 Nov 2014 11:37:00 +0000 Message-ID: <1417174620.23604.12.camel@citrix.com> References: <1417091674-8163-1-git-send-email-andrew.cooper3@citrix.com> <1417091674-8163-2-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1417091674-8163-2-git-send-email-andrew.cooper3@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: Andrew Cooper Cc: Wei Liu , Ian Jackson , Xen Coverity Team , Xen-devel List-Id: xen-devel@lists.xenproject.org On Thu, 2014-11-27 at 12:34 +0000, Andrew Cooper wrote: > The error handling from a failed memory allocation should return > PyErr_SetFromErrno(xc_error_obj); rather than simply calling it and continuing > to the memcpy() below, with the dest pointer being NULL. > > Furthermore, the context string is simply an input parameter to the hypercall, > and is not mutated anywhere along the way. The error handling elsewhere in > the function can be simplified by not duplicating it to start with. > > Signed-off-by: Andrew Cooper > Coverity-IDs: 1055305 1055721 > CC: Ian Campbell > CC: Ian Jackson > CC: Wei Liu > CC: Xen Coverity Team Acked-by: Ian Campbell This would have been far more obviously correct for 4.5 if you had stuck to fixing the issue in the first paragraph. > --- > tools/python/xen/lowlevel/xc/xc.c | 21 +++------------------ > 1 file changed, 3 insertions(+), 18 deletions(-) > > diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c > index d95d459..c70b388 100644 > --- a/tools/python/xen/lowlevel/xc/xc.c > +++ b/tools/python/xen/lowlevel/xc/xc.c > @@ -2126,8 +2126,6 @@ static PyObject *pyflask_context_to_sid(PyObject *self, PyObject *args, > { > xc_interface *xc_handle; > char *ctx; > - char *buf; > - uint32_t len; > uint32_t sid; > int ret; > > @@ -2137,28 +2135,15 @@ static PyObject *pyflask_context_to_sid(PyObject *self, PyObject *args, > &ctx) ) > return NULL; > > - len = strlen(ctx); > - > - buf = malloc(len); > - if (!buf) { > - errno = -ENOMEM; > - PyErr_SetFromErrno(xc_error_obj); > - } > - > - memcpy(buf, ctx, len); > - > xc_handle = xc_interface_open(0,0,0); > if (!xc_handle) { > - free(buf); > return PyErr_SetFromErrno(xc_error_obj); > } > - > - ret = xc_flask_context_to_sid(xc_handle, buf, len, &sid); > - > + > + ret = xc_flask_context_to_sid(xc_handle, ctx, strlen(ctx), &sid); > + > xc_interface_close(xc_handle); > > - free(buf); > - > if ( ret != 0 ) { > errno = -ret; > return PyErr_SetFromErrno(xc_error_obj);