From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH] tools/libxl: Fix two errors with libxl_userdata_unlink() Date: Wed, 24 Sep 2014 15:25:36 +0100 Message-ID: <5422D460.9080509@citrix.com> References: <1411558785-22311-1-git-send-email-andrew.cooper3@citrix.com> <1411568675.28127.43.camel@kazak.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1411568675.28127.43.camel@kazak.uk.xensource.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: Ian Campbell Cc: Wei Liu , Ian Jackson , Xen-devel List-Id: xen-devel@lists.xenproject.org On 24/09/14 15:24, Ian Campbell wrote: > On Wed, 2014-09-24 at 12:39 +0100, Andrew Cooper wrote: >> Coverity-ID: 1240235 >> * filename may be NULL, at which point calling unlink() would be unwise. > Oops! > >> Coverity-ID: 1240237 >> * Initalise rc to 0 to avoid returning stack junk in the success case. > Doing this right before the out: label is helpful since it helps the > compiler catch failure paths which forget to set rc. Good point - v2 incoming. ~Andrew > >> Signed-off-by: Andrew Cooper >> CC: Ian Campbell >> CC: Ian Jackson >> CC: Wei Liu >> --- >> tools/libxl/libxl_dom.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c >> index bd21841..11c2683 100644 >> --- a/tools/libxl/libxl_dom.c >> +++ b/tools/libxl/libxl_dom.c >> @@ -2097,7 +2097,7 @@ int libxl_userdata_unlink(libxl_ctx *ctx, uint32_t domid, >> const char *userdata_userid) >> { >> GC_INIT(ctx); >> - int rc; >> + int rc = 0; >> >> libxl__domain_userdata_lock *lock; >> const char *filename; >> @@ -2110,7 +2110,7 @@ int libxl_userdata_unlink(libxl_ctx *ctx, uint32_t domid, >> } >> >> filename = libxl__userdata_path(gc, domid, userdata_userid, "d"); >> - if (unlink(filename)) rc = ERROR_FAIL; >> + if (!filename || unlink(filename)) rc = ERROR_FAIL; >> >> libxl__unlock_domain_userdata(lock); >> out: >