zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH?] The here-doc that never ends
Date: Mon, 6 Jun 2022 22:31:55 -0700	[thread overview]
Message-ID: <CAH+w=7ZFnQu2=sPteu=ExiZRq-OR71am2W2iXkWHQS-rASOGkg@mail.gmail.com> (raw)

zsh -f

% true << (
>

Note the shell is now at a PS2 prompt.  The only way to escape the PS2
prompt is to type a closing paren, at which point you're at

heredoc>

But then gethere() is waiting for a single line consisting of the C
string "(\n)" which it is not possible to enter.  The only way out is
to interrupt.

Brute-force patch for this is below, but it seems like we should be
able to catch it sooner?  This appears to arise only because zsh
accepts <<(command) as well as < <(command) (note spacing).

Same effect with:

% true <<$'\n'

but there doesn't seem to be any good way to prevent that, and bash
5.0.17 behaves the same in that case.

diff --git a/Src/parse.c b/Src/parse.c
index d612b7e17..5054e59d5 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -2248,6 +2248,9 @@ par_redir(int *rp, char *idstring)
     struct heredocs **hd;
     int htype = type;

+    if (strchr(tokstr, '\n'))
+        YYERROR(ecused);
+
     /*
      * Add two here for the string to remember the HERE
      * terminator in raw and munged form.


                 reply	other threads:[~2022-06-07  5:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7ZFnQu2=sPteu=ExiZRq-OR71am2W2iXkWHQS-rASOGkg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).