From 95b95f9387d0dc8c8f0903a8c16d7d94c7a16175 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 18 Aug 2021 10:54:59 +0300 Subject: [PATCH 1/2] Drop arbitrary macro name minimum length limit (RhBug:1994223) Traditionally rpm has required user defined macro names to be at least three characters long, but outlaws all sorts of useful names like %cc for no particularly good reason - on unix a *lot* of commands are two characters, and then there are programming languages named R and whatnot. For macros starting with underscore, require one additional character though so `r` is okay and so is `_r` but plain `_` is not. The name validation and error reporting is buggy in multiple ways but not in the mood to chase all those now, this is just the bare minimum change. --- rpmio/macro.c | 4 ++-- tests/rpmmacro.at | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index 94ff5187db..c42694f410 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -601,8 +601,8 @@ validName(MacroBuf mb, const char *name, size_t namelen, const char *action) int rc = 0; int c; - /* Names must start with alphabetic or _ and be at least 3 chars */ - if (!((c = *name) && (risalpha(c) || c == '_') && (namelen) > 2)) { + /* Names must start with alphabetic, or _ and be at least 2 chars */ + if (!((c = *name) && (risalpha(c) || (c == '_' && namelen > 1)))) { mbErr(mb, 1, _("Macro %%%s has illegal name (%s)\n"), name, action); goto exit; } diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at index c0f1140871..fb6b21f4bb 100644 --- a/tests/rpmmacro.at +++ b/tests/rpmmacro.at @@ -891,7 +891,7 @@ AT_SETUP([macro file errors]) AT_KEYWORDS([macros]) AT_CHECK([ cat << EOF > macros.bad -%_i foo +%1 foo %multi \\ line\\ @@ -906,7 +906,7 @@ run rpm --macros "macros.bad" --eval "%foo" [0], [bar ], -[error: macros.bad: line 1: Macro %_i has illegal name (%define) +[error: macros.bad: line 1: Macro %1 has illegal name (%define) warning: macros.bad: line 8: Macro %bad needs whitespace before body ]) AT_CLEANUP From 830c55328f85f0cf6282a05454e4bb2a22c571d5 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 18 Aug 2021 11:09:11 +0300 Subject: [PATCH 2/2] Explicitly protect automatic macros from being redefined and undefined All current automatic macros are named in a way that do not pass the name check in validName(), but that's kinda implicit. Specifically test for ME_AUTO along with ME_BUILTIN. No functional change due to the implicit protection from the naming. --- rpmio/macro.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index c42694f410..eeeffa2b19 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -608,7 +608,7 @@ validName(MacroBuf mb, const char *name, size_t namelen, const char *action) } mep = findEntry(mb->mc, name, namelen, NULL); - if (mep && (*mep)->flags & ME_BUILTIN) { + if (mep && (*mep)->flags & (ME_BUILTIN|ME_AUTO)) { mbErr(mb, 1, _("Macro %%%s is a built-in (%s)\n"), name, action); goto exit; }