[SV 64402] Correct locating "," in ifeq/ifneq conditionals

Ensure that we correctly skip the entirety of a macro or function
reference when searching for the "," separator in an ifeq/ifneq
conditional, including using "$," and also "${foo,bar}".  Note that
this change means that parenthesis OTHER than those used for variable
expansion are not considered special, any longer.

* NEWS: Announce the change.
* src/read.c (conditional_line): Skip variable references when looking
  for "," and ensure that we match closing parens/braces properly.
* tests/scripts/features/conditionals: Add tests for this behavior.
This commit is contained in:
Paul Smith
2024-01-06 17:42:40 -05:00
parent 33932663b0
commit d86448fe5f
3 changed files with 72 additions and 12 deletions

View File

@@ -1672,13 +1672,27 @@ conditional_line (char *line, size_t len, const floc *flocp)
if (termin == ',')
{
int count = 0;
for (; *line != '\0'; ++line)
if (*line == '(')
++count;
else if (*line == ')')
--count;
else if (*line == ',' && count <= 0)
break;
char *delim = xmalloc (strlen (line));
while (*line != '\0')
{
if (*line == '$')
{
++line;
if (*line == '(')
delim[count++] = ')';
else if (*line == '{')
delim[count++] = '}';
}
else if (count == 0)
{
if (*line == ',')
break;
}
else if (*line == delim[count-1])
--count;
++line;
}
free (delim);
}
else
while (*line != '\0' && *line != termin)