Don't double-expand arguments to built-in macros (#311)

Double-expanding the output makes it rather impossible to reliably
handle filenames (and other content) with % characters in them.

Fixes: #313
This commit is contained in:
Panu Matilainen 2020-02-10 13:42:19 +02:00
parent b551b256ea
commit 47dbb3e070
2 changed files with 3 additions and 7 deletions

View File

@ -1166,7 +1166,6 @@ doFoo(MacroBuf mb, int chkexist, int negate, const char * f, size_t fn,
char *b = NULL; char *b = NULL;
int verbose = (rpmIsVerbose() != 0); int verbose = (rpmIsVerbose() != 0);
int expand = (g != NULL && gn > 0); int expand = (g != NULL && gn > 0);
int expandagain = 1;
/* Don't expand %{verbose:...} argument on false condition */ /* Don't expand %{verbose:...} argument on false condition */
if (STREQ("verbose", f, fn) && (verbose == negate)) if (STREQ("verbose", f, fn) && (verbose == negate))
@ -1224,7 +1223,6 @@ doFoo(MacroBuf mb, int chkexist, int negate, const char * f, size_t fn,
if (expr) { if (expr) {
free(buf); free(buf);
b = buf = expr; b = buf = expr;
expandagain = 0;
} else { } else {
mb->error = 1; mb->error = 1;
} }
@ -1242,11 +1240,7 @@ doFoo(MacroBuf mb, int chkexist, int negate, const char * f, size_t fn,
} }
if (b) { if (b) {
if (expandagain) { mbAppendStr(mb, b);
(void) expandMacro(mb, b, 0);
} else {
mbAppendStr(mb, b);
}
} }
free(buf); free(buf);
} }

View File

@ -263,6 +263,7 @@ AT_CHECK([
runroot rpm --eval "%{dirname}" runroot rpm --eval "%{dirname}"
runroot rpm --eval "%{dirname:}" runroot rpm --eval "%{dirname:}"
runroot rpm --eval "%{dirname:dir}" runroot rpm --eval "%{dirname:dir}"
runroot rpm --define '%xxx /hello/%%%%/world' --eval '%{dirname:%xxx}'
runroot rpm --eval "%{uncompress}" runroot rpm --eval "%{uncompress}"
runroot rpm --eval "%{uncompress:}" runroot rpm --eval "%{uncompress:}"
runroot rpm --eval "%{getncpus:}" runroot rpm --eval "%{getncpus:}"
@ -273,6 +274,7 @@ runroot rpm --eval "%{dump:foo}"
[1], [1],
[ [
dir dir
/hello/%%
], ],
[error: %dirname: argument expected [error: %dirname: argument expected