From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=azItImf1; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 8CB235A061C for ; Fri, 10 Apr 2026 03:03:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1775782993; bh=TXRV37WiMdQpri94jVFPj+VqDzMq3QrG8XrOptbAQl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=azItImf1lgxgm4zNkewqSuZpLrCRbBKGNHC79YpESCwWlPa34tbNUW6N0Vjqi+1iP Iu+hW0Mk95AG0a1nweY/tjIfB2HvhqSk8b2Xke1WpUgVyiOGfMKByl4fVseivr5wrc L/QVtOYHoO2sFOXh36jwag7IeGnHQ8wcigBwOkjMw8xc2v/nRcU1dfLO1xj59lay4M Az1O4c40luXFvnjec4eCjSASG3Z9x31NHHw5fYJsnSUUZw38pmwNfr0fzpgpLltcjf Myo+kkBmgAasiU5ISi9E7xIiBJjNqPKdA9NOb4ZwE0iZpPjEWt++BQXUF6TpJ0BhOJ IS8XbXMF363gg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fsJSx0lH0z4wd3; Fri, 10 Apr 2026 11:03:13 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 14/23] conf: Rework checking for garbage after a range Date: Fri, 10 Apr 2026 11:03:00 +1000 Message-ID: <20260410010309.736855-15-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260410010309.736855-1-david@gibson.dropbear.id.au> References: <20260410010309.736855-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 74WRTAPAUY5FAYZJ5XHCRITRAK6XMSPB X-Message-ID-Hash: 74WRTAPAUY5FAYZJ5XHCRITRAK6XMSPB X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: After parsing port ranges conf_ports_spec() checks if we've reached a chunk delimiter (',') to verify that there isn't extra garbage there. Rework how we do this to use the recently introduced chunk-end pointer. This has two advantages: 1) Small, but practical: we don't need to repeat what the valid delimiters are, that's already handled in the chunk splitting code. 2) Large, if theoretical: this will also give an error if port parsing overruns a chunk boundary. We don't really expect that to happen, but it would be very confusing if it did. strtoul(3), on which parse_port_range() is based does say it may accept thousands separators based on locale which means we can't be sure it will only accept strings of digits. Signed-off-by: David Gibson --- conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf.c b/conf.c index 0bc74e95..c3655824 100644 --- a/conf.c +++ b/conf.c @@ -264,7 +264,7 @@ static void conf_ports_spec(const struct ctx *c, if (parse_port_range(p, &p, &xrange)) goto bad; - if ((*p != '\0') && (*p != ',')) /* Garbage after the range */ + if (p != ep) /* Garbage after the range */ goto bad; for (i = xrange.first; i <= xrange.last; i++) @@ -303,7 +303,7 @@ static void conf_ports_spec(const struct ctx *c, mapped_range = orig_range; } - if ((*p != '\0') && (*p != ',')) /* Garbage after the ranges */ + if (p != ep) /* Garbage after the ranges */ goto bad; if (orig_range.first == 0) { -- 2.53.0