input: Eat rest of line upon reset
commit91a375576d37bb4db1eca48e6bf5bac0db6cc3fa
authorHerbert Xu <herbert@gondor.apana.org.au>
Tue, 3 Jan 2023 05:32:41 +0000 (3 13:32 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sun, 8 Jan 2023 12:03:08 +0000 (8 20:03 +0800)
treeb4c6495e8670a036c59ee06d2ac0946467437afe
parentc3b97c70d8ffec83122caf2bfd0489380610217c
input: Eat rest of line upon reset

Interactively, sh_error() doesn't terminate, so
  echo "|$(printf %10000s)echo bug" | sh -i
would read the first 8KiB, see that it's invalid, then jump back to the
parser, which would then read and execute the rest of the line as-if
it were the next line.

The fix for this is to explicitly consume the rest of the invalid line,
so that the next line observed is /actually/ the next line.

This is difficult to trigger accidentally right now, since we consume
the entire icanon line buffer at once (provided it's <8k, which it
~always is interactively), so we always observe one line at a time,
but the next patch would make even "| echo bug" blow up.

Reported-by: наб <nabijaczleweli@nabijaczleweli.xyz>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
src/input.c