From nobody Thu May 2 07:09:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504886171789585.0212031897628; Fri, 8 Sep 2017 08:56:11 -0700 (PDT) Received: from localhost ([::1]:46077 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqLda-0007or-Mi for importer@patchew.org; Fri, 08 Sep 2017 11:56:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53039) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqLba-0006TH-FY for qemu-devel@nongnu.org; Fri, 08 Sep 2017 11:54:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dqLbW-00047c-Jc for qemu-devel@nongnu.org; Fri, 08 Sep 2017 11:54:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35476) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dqLbW-00046J-Cf for qemu-devel@nongnu.org; Fri, 08 Sep 2017 11:54:02 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51B03883CD; Fri, 8 Sep 2017 15:54:01 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-116-125.ams2.redhat.com [10.36.116.125]) by smtp.corp.redhat.com (Postfix) with ESMTP id 778586AD35; Fri, 8 Sep 2017 15:54:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 51B03883CD Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dgilbert@redhat.com From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, samuel.thibault@ens-lyon.org, jan.kiszka@siemens.com Date: Fri, 8 Sep 2017 16:53:59 +0100 Message-Id: <20170908155359.27952-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 08 Sep 2017 15:54:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] slirp: Add explanation for hostfwd parsing failure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" e.g. ./x86_64-softmmu/qemu-system-x86_64 -nographic -netdev 'user,id=3Dvnet,host= fwd=3D:555.0.0.0:0-:22' qemu-system-x86_64: -netdev user,id=3Dvnet,hostfwd=3D:555.0.0.0:0-:22: Inva= lid host forwarding rule ':555.0.0.0:0-:22' (Bad host address) Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- net/slirp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/net/slirp.c b/net/slirp.c index 01ed21c006..d87664d42e 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -496,9 +496,11 @@ static int slirp_hostfwd(SlirpState *s, const char *re= dir_str, char buf[256]; int is_udp; char *end; + const char *fail_reason =3D ""; =20 p =3D redir_str; if (!p || get_str_sep(buf, sizeof(buf), &p, ':') < 0) { + fail_reason =3D "No : separators"; goto fail_syntax; } if (!strcmp(buf, "tcp") || buf[0] =3D=3D '\0') { @@ -506,35 +508,43 @@ static int slirp_hostfwd(SlirpState *s, const char *r= edir_str, } else if (!strcmp(buf, "udp")) { is_udp =3D 1; } else { + fail_reason =3D "Bad protocol name"; goto fail_syntax; } =20 if (!legacy_format) { if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) { + fail_reason =3D "Missing : separator"; goto fail_syntax; } if (buf[0] !=3D '\0' && !inet_aton(buf, &host_addr)) { + fail_reason =3D "Bad host address"; goto fail_syntax; } } =20 if (get_str_sep(buf, sizeof(buf), &p, legacy_format ? ':' : '-') < 0) { + fail_reason =3D "Bad host port separator"; goto fail_syntax; } host_port =3D strtol(buf, &end, 0); if (*end !=3D '\0' || host_port < 0 || host_port > 65535) { + fail_reason =3D "Bad host port"; goto fail_syntax; } =20 if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) { + fail_reason =3D "Missing guest address"; goto fail_syntax; } if (buf[0] !=3D '\0' && !inet_aton(buf, &guest_addr)) { + fail_reason =3D "Bad guest address"; goto fail_syntax; } =20 guest_port =3D strtol(p, &end, 0); if (*end !=3D '\0' || guest_port < 1 || guest_port > 65535) { + fail_reason =3D "Bad guest port"; goto fail_syntax; } =20 @@ -547,7 +557,8 @@ static int slirp_hostfwd(SlirpState *s, const char *red= ir_str, return 0; =20 fail_syntax: - error_setg(errp, "Invalid host forwarding rule '%s'", redir_str); + error_setg(errp, "Invalid host forwarding rule '%s' (%s)", redir_str, + fail_reason); return -1; } =20 --=20 2.13.5