From 8de699ee70020ad99e0a07ee107e446f84c7264a Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 28 Feb 2024 14:20:13 +0200 Subject: [PATCH] Issue a warning when passing arguments to non-parametric macros This should be an error for consistency with other macro argument checking but as there appear to be usages in the wild, make it a warning for now. Fixes: #2932 --- rpmio/macro.c | 6 ++++++ tests/rpmmacro.at | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/rpmio/macro.c b/rpmio/macro.c index 22e340fc0..fd30373b1 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -1716,6 +1716,12 @@ expandMacro(rpmMacroBuf mb, const char *src, size_t slen) } if (me->opts == NULL && !(me->flags & ME_FUNC)) { + if (g || (lastc && *lastc == '}')) { + /* XXX TODO: Make this an error in a few years */ + rpmMacroBufErr(mb, 0, + _("unexpected argument to non-parametric macro %%%s\n"), + me->name); + } /* Simple non-parametric macro */ doMacro(mb, me, NULL, NULL); s = se; diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at index 8c6e965f2..60cb0f96b 100644 --- a/tests/rpmmacro.at +++ b/tests/rpmmacro.at @@ -454,6 +454,27 @@ runroot rpm \ 0 0 ]) + +RPMTEST_CHECK([ +runroot rpm \ + --define 'zzz xxx' \ + --eval '%zzz' \ + --eval '%{zzz}' \ + --eval '%{zzz:}' \ + --eval '%{zzz }' \ + --eval '%{zzz aa}' +], +[0], +[xxx +xxx +xxx +xxx +xxx +], +[warning: unexpected argument to non-parametric macro %zzz +warning: unexpected argument to non-parametric macro %zzz +warning: unexpected argument to non-parametric macro %zzz +]) RPMTEST_CLEANUP AT_SETUP([string functions])