zsh-syntax-highlighting icon indicating copy to clipboard operation
zsh-syntax-highlighting copied to clipboard

main: Fix alias loops in nested lists (e.g. command substitution)

Open phy1729 opened this issue 3 years ago • 9 comments

alias ls='echo $(ls)' then ls will cause zsh to crash. This avoids that.

The idea is that we are still in the alias even when recursing into a nested list like a command substitution, so _highlight_list is the wrong place to local seen_alias.

phy1729 avatar Feb 25 '21 04:02 phy1729

The idea is that we are still in the alias even when recursing into a nested list like a command substitution, so _highlight_list is the wrong place to local seen_alias.

What about the opposite problem? Might some $seen_alias element remain set longer than it should?

danielshahaf avatar Feb 25 '21 08:02 danielshahaf

I can't imagine a scenario in which an alias is being expanded and in the course of expansion it is again eligible for expansion. That way lies madness^Wstack overflows.

phy1729 avatar Mar 01 '21 01:03 phy1729

The C code enforces that an alias be ineligible for expansion whilst it's being expanded. It's easy to see that: alias ls=ls works.

danielshahaf avatar Mar 01 '21 09:03 danielshahaf

I don't immediately follow how that's the same thing as what I asked, though. I'll look again later.

danielshahaf avatar Mar 01 '21 09:03 danielshahaf

Seems alias ls='eval ls' then ls will cause zsh to segfault. Of course it's possible to make such a construct not segfault; however, both with and without the patch z-sy-h will highlight the alias as such since we don't peek into eval.

The point being the only way for seen_alias to be set longer than it ought is if an alias is eligible for expansion while it is itself being expanded. That seems to only be the case with eval.

phy1729 avatar Mar 02 '21 04:03 phy1729

That answers my question, then. I don't have any other review comments.

Would you report the segfault, please? Either upstream or here, whichever's appropriate. Thanks!

danielshahaf avatar Mar 02 '21 17:03 danielshahaf

I don't get a segfault. Both with and without z-sy-h, I get this:

% alias ls='eval ls' % ls zsh: job table full or recursion limit exceeded

I did press <Enter> at the end of the second line.

danielshahaf avatar Mar 02 '21 20:03 danielshahaf

I don't get a segfault. Both with and without z-sy-h, I get this:

% alias ls='eval ls' % ls zsh: job table full or recursion limit exceeded

With PRINT_EXIT_VALUE in effect too, I see exactly 999 copies of "zsh: exit 1" printed.

That looks like it might be MAX_MAXJOBS: https://github.com/zsh-users/zsh/blob/5ede2c55f144593c16498c3131a76e188114a9c6/Src/jobs.c#L2061-L2066

danielshahaf avatar Mar 02 '21 20:03 danielshahaf

Should this be milestoned 0.8.0?

danielshahaf avatar Jul 16 '21 14:07 danielshahaf