From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ab9cO-00006L-Ml for qemu-devel@nongnu.org; Wed, 02 Mar 2016 11:27:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ab9cN-0007rT-UD for qemu-devel@nongnu.org; Wed, 02 Mar 2016 11:27:20 -0500 Date: Wed, 2 Mar 2016 11:27:09 -0500 From: Jeff Cody Message-ID: <20160302162709.GH26318@localhost.localdomain> References: <56D71109.7060009@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56D71109.7060009@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 1/1] block/sheepdog: fix argument passed to qemu_strtoul() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: kwolf@redhat.com, qemu-block@nongnu.org, mitake.hitoshi@lab.ntt.co.jp, qemu-devel@nongnu.org, v.tolstov@selfip.ru, mreitz@redhat.com, namei.unix@gmail.com On Wed, Mar 02, 2016 at 05:12:57PM +0100, Paolo Bonzini wrote: > > > On 02/03/2016 17:09, Jeff Cody wrote: > > + ret = qemu_strtoul(snapshot_id, NULL, 10, &snap_id); > > + if (ret) { > > + error_setg_errno(errp, -ret, "Invalid snapshot ID: %s", > > + snapshot_id ? snapshot_id : ""); > > + return ret; > > + } > > + > > + if (snap_id > UINT32_MAX) { > > + error_setg_errno(errp, EINVAL, "Snapshot ID numeric value %" PRId64 > > + " exceeds Sheepdog maximum of %" PRId32, snap_id, > > + UINT32_MAX); > > + return -EINVAL; > > } > > I think including the errno produces a worse error message ("Invalid > snapshot ID: foo: Invalid argument" or something like that), and also Hey, if the user enters invalid input, they deserve a cryptic error message! Oh, alright - sent a v3 :-) > the error should be the same for an id of 10^10 (within uint64_t bounds) > or 10^30 (outside the bounds). So you could just use > > if (ret < 0 || snap_id > UINT32_MAX) { > error_setg(errp, "Invalid snapshot ID: %s", > snapshot_id ? snapshot_id : ""); > return -EINVAL; > } > > Thanks, > > Paolo