dfilter: Don't parse invalid characters in macro names

We haven't allowed anything other than alphanumerics or `_`
in macro names since at least 2007
(commit 8e849698a3)
so the better error message if a `-` is included is to say
that it's an invalid character, not that a macro with that
name doesn't exist.

We can also stop parsing at that point, which is more efficient.

That it was allowed at this point was a legacy of when field
references were handled using the macro code instead of separate
lexical elements, pre commit 260942e170.
(#17599)

Just use the same macro for valid characters in a macro name
in the two syntax forms. It's unlikely that we'll start allowing
`.` in macro names, and if we do, we'd have to revisit the
checking for the $macro(args,...) syntax as well.
This commit is contained in:
John Thacker 2024-01-23 07:13:18 -05:00
parent 0755cde944
commit b05def7a50
1 changed files with 4 additions and 4 deletions

View File

@ -166,7 +166,7 @@ static char* dfilter_macro_apply_recurse(const char* text, unsigned depth, df_er
open_c = 0; \
} while(0)
#define NAME_PARENS_CHAR(c) (g_ascii_isalnum(c) || (c) == '_')
#define MACRO_NAME_CHAR(c) (g_ascii_isalnum(c) || (c) == '_')
if (error != NULL)
*error = NULL;
@ -215,7 +215,7 @@ static char* dfilter_macro_apply_recurse(const char* text, unsigned depth, df_er
goto finish;
default:
if (NAME_PARENS_CHAR(c)) {
if (MACRO_NAME_CHAR(c)) {
/* Possible macro of the form $macro_name() */
args = g_ptr_array_new();
arg = g_string_sized_new(32);
@ -236,7 +236,7 @@ static char* dfilter_macro_apply_recurse(const char* text, unsigned depth, df_er
}
case NAME:
{
if ( g_ascii_isalnum(c) || c == '_' || c == '-' || c == '.' ) {
if (MACRO_NAME_CHAR(c)) {
g_string_append_c(name,c);
} else if ( c == ':') {
state = ARGS;
@ -268,7 +268,7 @@ static char* dfilter_macro_apply_recurse(const char* text, unsigned depth, df_er
}
case NAME_PARENS:
{
if (NAME_PARENS_CHAR(c)) {
if (MACRO_NAME_CHAR(c)) {
g_string_append_c(name,c);
} else if ( c == '(' || c == '{') {
state = ARGS;