summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2023-03-19 16:43:45 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2023-03-19 16:43:45 +0000
commit51864c134f3693dc4f3452f452bb8c5845c20c2f (patch)
tree2d268637149ef073ab1d6c1baeb53b5461f955c3 /usr.sbin/smtpd
parent7e0cb282dceb92858e880a271b66b59d4eb2a061 (diff)
mda_expand_format: simplify token name extraction for %{name}
It is simpler to compute the length based on the start and end pointers and pass that value to memcpy(), adding an explicit NUL terminator after copying. OK op@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r--usr.sbin/smtpd/mda_variables.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/usr.sbin/smtpd/mda_variables.c b/usr.sbin/smtpd/mda_variables.c
index 7c14d2eb551..0f2be7722c8 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.8 2023/03/19 01:43:11 millert Exp $ */
+/* $OpenBSD: mda_variables.c,v 1.9 2023/03/19 16:43:44 millert Exp $ */
/*
* Copyright (c) 2011-2017 Gilles Chehade <gilles@poolp.org>
@@ -243,7 +243,7 @@ mda_expand_format(char *buf, size_t len, const struct deliver *dlv,
char exptok[EXPAND_BUFFER];
ssize_t exptoklen;
char token[MAXTOKENLEN];
- size_t ret, tmpret;
+ size_t ret, tmpret, toklen;
if (len < sizeof tmpbuf) {
log_warnx("mda_expand_format: tmp buffer < rule buffer");
@@ -268,7 +268,6 @@ mda_expand_format(char *buf, size_t len, const struct deliver *dlv,
pbuf += 2;
}
-
/* expansion loop */
for (; *pbuf && ret < sizeof tmpbuf; ret += tmpret) {
if (*pbuf == '%' && *(pbuf + 1) == '%') {
@@ -285,17 +284,16 @@ mda_expand_format(char *buf, size_t len, const struct deliver *dlv,
}
/* %{...} otherwise fail */
- if (*(pbuf+1) != '{' || (ebuf = strchr(pbuf+1, '}')) == NULL)
+ if ((ebuf = strchr(pbuf+2, '}')) == NULL)
return 0;
/* extract token from %{token} */
- if ((size_t)(ebuf - pbuf) - 1 >= sizeof token)
+ toklen = ebuf - (pbuf+2);
+ if (toklen >= sizeof token)
return 0;
- memcpy(token, pbuf+2, ebuf-pbuf-1);
- if (strchr(token, '}') == NULL)
- return 0;
- *strchr(token, '}') = '\0';
+ memcpy(token, pbuf+2, toklen);
+ token[toklen] = '\0';
exptoklen = mda_expand_token(exptok, sizeof exptok, token, dlv,
ui, mda_command);