Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backslashes in anacron commands are ignored unless at the end of the line (i.e. for continuation) #54

Closed
Ian2020 opened this issue Mar 1, 2020 · 1 comment

Comments

@Ian2020
Copy link
Contributor

Ian2020 commented Mar 1, 2020

When anacron parses a line in anacrontab it accidentally ignores any backslashes which are not followed by a newline and so they are removed from the command that is run. I came across this whilst trying to use the -exec action of the find command which requires a backslash semi-colon \; to terminate it correctly.

As an example consider an anacrontab line such as:

1 0 report echo "Can you see these backslashes? \\\\"

The backslashes are never output. Looking in anacron/readtab.c, function read_tab_line looks like this:

static char *
read_tab_line (void)
/* Read one line and return a pointer to it.
Return NULL if no more lines.
 */
{
    int c, prev=0;

    if (feof(tab)) return NULL;
    while (1)
    {
	c = getc(tab);
	if ((c == '\n' && prev != '\\') || c == EOF)
	{
	    if (0 != prev) obstack_1grow(&input_o, (char)prev);
	    break;
	}

	if ('\\' != prev && 0 != prev && '\n' != prev) obstack_1grow(&input_o, (char)prev);
	else if ('\n' == prev) obstack_1grow(&input_o, ' ');

	prev = c;
    }
    if (ferror(tab)) die_e("Error reading %s", anacrontab);
    obstack_1grow(&input_o, '\0');
    return obstack_finish(&input_o);
}

As far as I can tell whenever we examine a backslash i.e. prev == '\\' there's no way if can be added to input_o due to all the guards against it. So it just gets skipped over?

@t8m
Copy link
Member

t8m commented Aug 3, 2020

Fixed by a merged #55

@t8m t8m closed this as completed Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants