From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id B03801FF153 for ; Wed, 17 Jun 2026 09:49:38 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6A50218397; Wed, 17 Jun 2026 09:49:38 +0200 (CEST) From: Dominik Csapak To: pmg-devel@lists.proxmox.com Subject: [PATCH log-tracker v2 2/3] parse_qid{_prefix}: remove 'max' parameter Date: Wed, 17 Jun 2026 09:47:49 +0200 Message-ID: <20260617074934.955079-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260617074934.955079-1-d.csapak@proxmox.com> References: <20260617074934.955079-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.049 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [main.rs] Message-ID-Hash: XE65EJAOFVULTDUUBO667KC6W4WS5EM5 X-Message-ID-Hash: XE65EJAOFVULTDUUBO667KC6W4WS5EM5 X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: it was always called with the same value anyway, so just use the constant directly in parse_qid and avoid having to pass it from outside. Signed-off-by: Dominik Csapak --- new in v2 src/main.rs | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index 89d2768..3b815cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -269,7 +269,7 @@ fn handle_postscreen_message(msg: &[u8], parser: &mut Parser, complete_line: &[u // these only appear in the 'after-queue filter' case or when the mail is // 'accepted' in the 'before-queue filter' case fn handle_qmgr_message(msg: &[u8], parser: &mut Parser, complete_line: &[u8]) { - let (qid, data) = match parse_qid_prefix(msg, POSTFIX_QID_MAX_LEN) { + let (qid, data) = match parse_qid_prefix(msg) { Some(t) => t, None => return, }; @@ -329,7 +329,7 @@ fn handle_lmtp_message(msg: &[u8], parser: &mut Parser, complete_line: &[u8]) { return; } - let (qid, data) = match parse_qid_prefix(msg, POSTFIX_QID_MAX_LEN) { + let (qid, data) = match parse_qid_prefix(msg) { Some((q, t)) => (q, t), None => return, }; @@ -638,7 +638,7 @@ fn handle_smtpd_message(msg: &[u8], parser: &mut Parser, complete_line: &[u8]) { // with none of the other messages matching, we try for a QID to match the // corresponding QEntry to the SEntry - let (qid, data) = match parse_qid_prefix(msg, POSTFIX_QID_MAX_LEN) { + let (qid, data) = match parse_qid_prefix(msg) { Some(t) => t, None => return, }; @@ -668,7 +668,7 @@ fn handle_smtpd_message(msg: &[u8], parser: &mut Parser, complete_line: &[u8]) { // happens before the mail is passed to qmgr (after-queue or before-queue // accepted only) fn handle_cleanup_message(msg: &[u8], parser: &mut Parser, complete_line: &[u8]) { - let (qid, data) = match parse_qid_prefix(msg, POSTFIX_QID_MAX_LEN) { + let (qid, data) = match parse_qid_prefix(msg) { Some(t) => t, None => return, }; @@ -2137,9 +2137,9 @@ const POSTFIX_QID_MAX_LEN: usize = 25; /// alphabet, and pmg-smtp-filter IDs are likewise alphanumeric. The scan stops at /// the first non-alphanumeric byte (the `:` or `)` delimiter that normally follows /// the queue ID); a run longer than `max` with no delimiter is truncated to `max`. -fn parse_qid(data: &[u8], max: usize) -> Option<(&[u8], &[u8])> { +fn parse_qid(data: &[u8]) -> Option<(&[u8], &[u8])> { // to simplify limit max to data.len() - let max = max.min(data.len()); + let max = POSTFIX_QID_MAX_LEN.min(data.len()); // take at most max, find the first non-alphanumeric byte match data .iter() @@ -2161,8 +2161,8 @@ fn parse_qid(data: &[u8], max: usize) -> Option<(&[u8], &[u8])> { /// /// Requiring the delimiter keeps foreign lines, like the output a custom check script logs under /// the pmg-smtp-filter identifier, from panicking the parser or being recorded under a bogus ID. -fn parse_qid_prefix(msg: &[u8], max: usize) -> Option<(&[u8], &[u8])> { - let (qid, data) = parse_qid(msg, max)?; +fn parse_qid_prefix(msg: &[u8]) -> Option<(&[u8], &[u8])> { + let (qid, data) = parse_qid(msg)?; Some((qid, data.strip_prefix(b": ")?)) } @@ -2434,13 +2434,13 @@ fn find_lowercase(data: &[u8], needle: &[u8]) -> Option { mod tests { use crate::parse_pmg_smtp_filter_qid; - use super::{POSTFIX_QID_MAX_LEN, parse_qid, parse_qid_prefix, rotated_logfile}; + use super::{parse_qid, parse_qid_prefix, rotated_logfile}; #[test] fn parse_short_hex_qid() { // legacy, short hexadecimal postfix queue ID assert_eq!( - parse_qid(b"0022C3801B5: removed", POSTFIX_QID_MAX_LEN), + parse_qid(b"0022C3801B5: removed"), Some((&b"0022C3801B5"[..], &b": removed"[..])), ); } @@ -2450,7 +2450,7 @@ mod tests { // postfix long queue ID (enable_long_queue_ids = yes) drawn from the // base-52 alphabet, i.e. containing non-hex letters assert_eq!( - parse_qid(b"4Zk8mP2gqRz: removed", POSTFIX_QID_MAX_LEN), + parse_qid(b"4Zk8mP2gqRz: removed"), Some((&b"4Zk8mP2gqRz"[..], &b": removed"[..])), ); } @@ -2460,7 +2460,7 @@ mod tests { // worst case long queue ID: 7 sec + 4 usec + 'z' + 12-char base-51 inode // (64-bit) = 24 chars; it must not be truncated by POSTFIX_QID_MAX_LEN assert_eq!( - parse_qid(b"4Zk8mP72gqRzLp7Wn3Yt8Kc5: removed", POSTFIX_QID_MAX_LEN), + parse_qid(b"4Zk8mP72gqRzLp7Wn3Yt8Kc5: removed"), Some((&b"4Zk8mP72gqRzLp7Wn3Yt8Kc5"[..], &b": removed"[..])), ); } @@ -2494,13 +2494,13 @@ mod tests { #[test] fn reject_too_short_qid() { // fewer than 5 leading queue-id characters is not a valid queue ID - assert_eq!(parse_qid(b"ab: x", POSTFIX_QID_MAX_LEN), None); + assert_eq!(parse_qid(b"ab: x"), None); } #[test] fn qid_prefix_parses_regular_entries() { assert_eq!( - parse_qid_prefix(b"0022C3801B5: removed", POSTFIX_QID_MAX_LEN), + parse_qid_prefix(b"0022C3801B5: removed"), Some((&b"0022C3801B5"[..], &b"removed"[..])), ); } @@ -2509,14 +2509,11 @@ mod tests { fn qid_prefix_rejects_lines_without_delimiter() { // foreign lines under a matched syslog identifier, like the output of a custom check // script, must not be mistaken for an entry: a bare delimiter at the end of the line ... - assert_eq!(parse_qid_prefix(b"DEBUG:", 25), None); + assert_eq!(parse_qid_prefix(b"DEBUG:"), None); // ... a delimiter without the following space ... - assert_eq!( - parse_qid_prefix(b"DEBUG:Module loader, version 1088", 25), - None - ); + assert_eq!(parse_qid_prefix(b"DEBUG:Module loader, version 1088"), None); // ... and no delimiter at all - assert_eq!(parse_qid_prefix(b"DEBUGOUTPUT", 25), None); + assert_eq!(parse_qid_prefix(b"DEBUGOUTPUT"), None); } #[test] -- 2.47.3