From patchwork Wed Mar 16 17:38:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 8603141 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 345D39F6E1 for ; Wed, 16 Mar 2016 17:39:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 96D1E202A1 for ; Wed, 16 Mar 2016 17:39:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 699402020F for ; Wed, 16 Mar 2016 17:39:03 +0000 (UTC) Received: from localhost ([::1]:57843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agFPS-00025R-Sy for patchwork-qemu-devel@patchwork.kernel.org; Wed, 16 Mar 2016 13:39:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agFPG-0001ss-Jd for qemu-devel@nongnu.org; Wed, 16 Mar 2016 13:38:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agFPF-0007dF-LA for qemu-devel@nongnu.org; Wed, 16 Mar 2016 13:38:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58515) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agFP8-0007Zp-Kr; Wed, 16 Mar 2016 13:38:42 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 4341980508; Wed, 16 Mar 2016 17:38:42 +0000 (UTC) Received: from localhost (ovpn-112-65.phx2.redhat.com [10.3.112.65]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2GHceIM015503 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA256 bits=256 verify=NO); Wed, 16 Mar 2016 13:38:41 -0400 From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 16 Mar 2016 13:38:37 -0400 Message-Id: <1458149918-13531-2-git-send-email-jcody@redhat.com> In-Reply-To: <1458149918-13531-1-git-send-email-jcody@redhat.com> References: <1458149918-13531-1-git-send-email-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 1/2] block/sheepdog: fix argument passed to qemu_strtoul() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 accommodate the full size in qemu_strtoul(). This patch also adds more meaningful error handling to the qemu_strtoul() call, and subsequent results. Reported-by: Paolo Bonzini Signed-off-by: Jeff Cody Reviewed-by: Max Reitz Reviewed-by: Hitoshi Mitake Message-id: e56fc50abedd9a112e0683342c8eafda063cd2f9.1456935548.git.jcody@redhat.com --- block/sheepdog.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index a6e98a5..06ae3ba 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2549,7 +2549,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; @@ -2571,12 +2571,15 @@ 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)) { - return -1; + ret = qemu_strtoul(snapshot_id, NULL, 10, &snap_id); + if (ret || snap_id > UINT32_MAX) { + error_setg(errp, "Invalid snapshot ID: %s", + snapshot_id ? snapshot_id : ""); + return -EINVAL; } if (snap_id) { - hdr.snapid = snap_id; + hdr.snapid = (uint32_t) snap_id; } else { pstrcpy(snap_tag, sizeof(snap_tag), snapshot_id); pstrcpy(buf + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, snap_tag);