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=GfcFebLS; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 6042B5A0275 for ; Tue, 07 Apr 2026 05:16:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1775531792; bh=0Ye3j7Uk0eElw2ZWDTAnTfFXw5pmIgmzsXPWnPCyCTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GfcFebLSP3VOe8SOdl1JiBSpaXifMZV/tenK9T0P0ciSVkxuDYGKvHAiqQJsmf/Gb oQ+XJDuWDNL70dOb2zIAPnaRGX7c60l4FqLj1sikFFXbkjli+zGy3Fpud6XJhGt0H6 QFFq1gMbRhjbKkZtABNlVDTjUaDFUUgHf/+ODndo1YXvjjKldMbmONsMGKTsJZvp6o jQZhdX8yCUvbBYhcKQWjVnQTsWkv4L9hZSAPyzi6g3rfb1oo7lWHSVtMDp9tTzOf9H 0GY8Xo8oOVhcLnTHqCG+Z84Qut82YbevkXgo55vJwhGhFLNE0EdQJVaXha/LDUu5Ek W5A19JvWO9Kog== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fqWZ86HB8z4wLJ; Tue, 07 Apr 2026 13:16:32 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 14/18] conf: Rework checking for garbage after a range Date: Tue, 7 Apr 2026 13:16:26 +1000 Message-ID: <20260407031630.2457081-15-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260407031630.2457081-1-david@gibson.dropbear.id.au> References: <20260407031630.2457081-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: TQXLKVMT2TKIQZU3TLICIC7OBH5OZDCR X-Message-ID-Hash: TQXLKVMT2TKIQZU3TLICIC7OBH5OZDCR 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 introduces 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 given an error if port parsing overruns a chunk boundary. We don't really expect that to happen, but it would give very confusing behaviour if it did. strtoul(3), on which parse_port_range() is based does say it may accept thousands separators based on locale which means can't entirely 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 1ab1b071..51612047 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