From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ab8rg-0004gK-JI for qemu-devel@nongnu.org; Wed, 02 Mar 2016 10:39:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ab8rf-0008BL-PQ for qemu-devel@nongnu.org; Wed, 02 Mar 2016 10:39:04 -0500 Date: Wed, 2 Mar 2016 10:38:55 -0500 From: Jeff Cody Message-ID: <20160302153855.GF26318@localhost.localdomain> References: <780d0c59f2993cec4a0931df93b9fe12cb5d0f46.1456931418.git.jcody@redhat.com> <56D70663.7030202@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56D70663.7030202@redhat.com> Subject: Re: [Qemu-devel] [Qemu-block] [PATCH 1/1] block/sheepdog: fix argument passed to qemu_strtoul() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: kwolf@redhat.com, qemu-block@nongnu.org, mitake.hitoshi@lab.ntt.co.jp, qemu-devel@nongnu.org, v.tolstov@selfip.ru, namei.unix@gmail.com, pbonzini@redhat.com On Wed, Mar 02, 2016 at 04:27:31PM +0100, Max Reitz wrote: > On 02.03.2016 16:16, Jeff Cody wrote: > > The function qemu_strtoul() reads 'unsigned long' sized data, > > which is larger than uint32_t on 64-bit machines. > > > > Even though the snap_id field in the header is 32-bits, we must > > accomodate the full size in qemu_strtoul(). > > > > Reported-by: Paolo Bonzini > > Signed-off-by: Jeff Cody > > --- > > block/sheepdog.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/block/sheepdog.c b/block/sheepdog.c > > index 8739acc..c6bf900 100644 > > --- a/block/sheepdog.c > > +++ b/block/sheepdog.c > > @@ -2543,7 +2543,7 @@ static int sd_snapshot_delete(BlockDriverState *bs, > > const char *name, > > Error **errp) > > { > > - uint32_t snap_id = 0; > > + unsigned long snap_id = 0; > > char snap_tag[SD_MAX_VDI_TAG_LEN]; > > Error *local_err = NULL; > > int fd, ret; > > @@ -2565,12 +2565,12 @@ static int sd_snapshot_delete(BlockDriverState *bs, > > memset(buf, 0, sizeof(buf)); > > memset(snap_tag, 0, sizeof(snap_tag)); > > pstrcpy(buf, SD_MAX_VDI_LEN, s->name); > > - if (qemu_strtoul(snapshot_id, NULL, 10, (unsigned long *)&snap_id)) { > > + if (qemu_strtoul(snapshot_id, NULL, 10, &snap_id)) { > > return -1; > > } > > > > if (snap_id) { > > - hdr.snapid = snap_id; > > + hdr.snapid = (uint32_t) snap_id; > > Maybe we should do an overflow check before? > Probably not a bad idea - easy enough, and that would prevent a false positive match due to id truncation. I'll spin a v2. Jeff