From 130baa166af2c29b71fd864083f12acf8a95f46a Mon Sep 17 00:00:00 2001 From: jtt Date: Fri, 3 Apr 2026 10:18:58 +0000 Subject: [PATCH] smtpd: fix using modifiers with partial expansion in format specifiers Nits on the manpage and ok op@ --- usr.sbin/smtpd/mda_variables.c | 5 +++-- usr.sbin/smtpd/smtpd.conf.5 | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/usr.sbin/smtpd/mda_variables.c b/usr.sbin/smtpd/mda_variables.c index 0542f95de33..3e32fd7467f 100644 --- a/usr.sbin/smtpd/mda_variables.c +++ b/usr.sbin/smtpd/mda_variables.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mda_variables.c,v 1.10 2024/04/23 13:34:51 jsg Exp $ */ +/* $OpenBSD: mda_variables.c,v 1.11 2026/04/03 10:18:58 jtt Exp $ */ /* * Copyright (c) 2011-2017 Gilles Chehade @@ -94,7 +94,8 @@ mda_expand_token(char *dest, size_t len, const char *token, return -1; /* token:mod_1,mod_2,mod_n -> extract modifiers */ - mods = strchr(rbracket + 1, ':'); + if ((mods = strchr(rbracket + 1, ':')) != NULL) + *mods++ = '\0'; } else { if ((mods = strchr(rtoken, ':')) != NULL) *mods++ = '\0'; diff --git a/usr.sbin/smtpd/smtpd.conf.5 b/usr.sbin/smtpd/smtpd.conf.5 index 1cdaf067c55..876ef0774ff 100644 --- a/usr.sbin/smtpd/smtpd.conf.5 +++ b/usr.sbin/smtpd/smtpd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: smtpd.conf.5,v 1.281 2026/03/12 07:46:08 jsg Exp $ +.\" $OpenBSD: smtpd.conf.5,v 1.282 2026/04/03 10:18:58 jtt Exp $ .\" .\" Copyright (c) 2008 Janne Johansson .\" Copyright (c) 2009 Jacek Masiulaniec @@ -17,7 +17,7 @@ .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .\" -.Dd $Mdocdate: March 12 2026 $ +.Dd $Mdocdate: April 3 2026 $ .Dt SMTPD.CONF 5 .Os .Sh NAME @@ -1144,6 +1144,14 @@ For example, with recipient .It %{rcpt:lowercase|strip} Ta expands to Dq user@example.org .El .Pp +Modifiers and partial expansion can be used together. +In such cases, the modifiers are applied before the partial expansion. +For example, with sender +.Dq owner-tech+M123456@openbsd.org : +.Bl -column %{sender.user[6:]:strip} -offset indent +.It %{sender.user[6:]:strip} Ta expands to Dq tech +.El +.Pp For security concerns, expanded values are sanitized and potentially dangerous characters are replaced with .Sq \&: .