From patchwork Tue Jun 24 22:06:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 363749 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AB5DE1400B9 for ; Wed, 25 Jun 2014 08:07:35 +1000 (EST) Received: from localhost ([::1]:34000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzYsH-0000nn-GZ for incoming@patchwork.ozlabs.org; Tue, 24 Jun 2014 18:07:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzYrm-0008R3-OY for qemu-devel@nongnu.org; Tue, 24 Jun 2014 18:07:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WzYrg-0000c2-2r for qemu-devel@nongnu.org; Tue, 24 Jun 2014 18:07:02 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:36230 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzYrf-0000bW-Nu for qemu-devel@nongnu.org; Tue, 24 Jun 2014 18:06:56 -0400 Received: (qmail 4996 invoked by uid 89); 24 Jun 2014 22:06:53 -0000 Received: from [82.141.1.145] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.98.4/19125. hbedv: 8.3.20.14/7.11.156.158. spamassassin: 3.4.0. Clear:RC:1(82.141.1.145):SA:0(-1.2/5.0):. Processed in 1.383639 secs); 24 Jun 2014 22:06:53 -0000 Received: from ns.kamp-intra.net (HELO dns.kamp-intra.net) ([82.141.1.145]) by mx01.kamp.de with SMTP; 24 Jun 2014 22:06:52 -0000 X-GL_Whitelist: yes Received: from lieven-pc.kamp-intra.net (lieven-pc.kamp-intra.net [172.21.12.60]) by dns.kamp-intra.net (Postfix) with ESMTP id 1B1272068F; Wed, 25 Jun 2014 00:06:02 +0200 (CEST) Received: by lieven-pc.kamp-intra.net (Postfix, from userid 1000) id 148686194C; Wed, 25 Jun 2014 00:06:02 +0200 (CEST) From: Peter Lieven To: qemu-devel@nongnu.org Date: Wed, 25 Jun 2014 00:06:00 +0200 Message-Id: <1403647561-19534-2-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1403647561-19534-1-git-send-email-pl@kamp.de> References: <1403647561-19534-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a02:248:0:51::16 Cc: kwolf@redhat.com, stefanha@redhat.com, Peter Lieven , ronniesahlberg@gmail.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCHv3 1/2] block/nfs: fix url parameter checking 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org this patch fixes the incorrect usage of strncmp and adds simple error checking by means of parse_uint_full instead of atoi for the supplied URL parameters. Signed-off-by: Peter Lieven Reviewed-by: Eric Blake --- block/nfs.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/block/nfs.c b/block/nfs.c index ec43201..0b44483 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -304,17 +304,23 @@ static int64_t nfs_client_open(NFSClient *client, const char *filename, qp = query_params_parse(uri->query); for (i = 0; i < qp->n; i++) { + unsigned long long val; if (!qp->p[i].value) { error_setg(errp, "Value for NFS parameter expected: %s", qp->p[i].name); goto fail; } - if (!strncmp(qp->p[i].name, "uid", 3)) { - nfs_set_uid(client->context, atoi(qp->p[i].value)); - } else if (!strncmp(qp->p[i].name, "gid", 3)) { - nfs_set_gid(client->context, atoi(qp->p[i].value)); - } else if (!strncmp(qp->p[i].name, "tcp-syncnt", 10)) { - nfs_set_tcp_syncnt(client->context, atoi(qp->p[i].value)); + if (parse_uint_full(qp->p[i].value, &val, 0)) { + error_setg(errp, "Illegal value for NFS parameter: %s", + qp->p[i].name); + goto fail; + } + if (!strcmp(qp->p[i].name, "uid")) { + nfs_set_uid(client->context, val); + } else if (!strcmp(qp->p[i].name, "gid")) { + nfs_set_gid(client->context, val); + } else if (!strcmp(qp->p[i].name, "tcp-syncnt")) { + nfs_set_tcp_syncnt(client->context, val); } else { error_setg(errp, "Unknown NFS parameter name: %s", qp->p[i].name);