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.
This commit is contained in:
Panu Matilainen 2021-08-18 10:54:59 +03:00
parent fd57fc7162
commit 80ca959e32
2 changed files with 4 additions and 4 deletions

View File

@ -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;
}

View File

@ -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