summaryrefslogtreecommitdiff
path: root/bin/csh
diff options
context:
space:
mode:
authoranton <anton@cvs.openbsd.org>2017-08-30 06:42:22 +0000
committeranton <anton@cvs.openbsd.org>2017-08-30 06:42:22 +0000
commitd4324463f4318e2f73a7fb1ea3e50e0a5142422a (patch)
treea9a3ac651f5e2d49dca84513fc40bdda4c93e178 /bin/csh
parent2f8a066f71d869074f7a789405f23c99d28c7f21 (diff)
Fix pasting of long (>BUFSIZ) lines in csh with filec enabled. NUL-terminating
the input buffer instructs csh that the buffer contains a complete command. This is wrong and should only happen when buffer is not full, otherwise more data has to be read in order form a complete command. While here, do not print the prompt again when the input exceeds the input buffer and while inserting a line continuation (backslash).
Diffstat (limited to 'bin/csh')
-rw-r--r--bin/csh/csh.c5
-rw-r--r--bin/csh/csh.h3
-rw-r--r--bin/csh/file.c18
-rw-r--r--bin/csh/func.c5
4 files changed, 22 insertions, 9 deletions
diff --git a/bin/csh/csh.c b/bin/csh/csh.c
index 517f11413b6..5df655ade5d 100644
--- a/bin/csh/csh.c
+++ b/bin/csh/csh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: csh.c,v 1.40 2017/07/26 19:15:09 anton Exp $ */
+/* $OpenBSD: csh.c,v 1.41 2017/08/30 06:42:21 anton Exp $ */
/* $NetBSD: csh.c,v 1.14 1995/04/29 23:21:28 mycroft Exp $ */
/*-
@@ -1008,7 +1008,8 @@ process(bool catch)
* read fresh stuff. Otherwise, we are rereading input and don't
* need or want to prompt.
*/
- if (!filec && aret == F_SEEK && fseekp == feobp)
+ needprompt = aret == F_SEEK && fseekp == feobp;
+ if (!filec && needprompt)
printprompt();
(void) fflush(cshout);
}
diff --git a/bin/csh/csh.h b/bin/csh/csh.h
index 601b7bb9772..b830d810681 100644
--- a/bin/csh/csh.h
+++ b/bin/csh/csh.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: csh.h,v 1.29 2017/07/22 09:37:21 anton Exp $ */
+/* $OpenBSD: csh.h,v 1.30 2017/08/30 06:42:21 anton Exp $ */
/* $NetBSD: csh.h,v 1.9 1995/03/21 09:02:40 cgd Exp $ */
/*-
@@ -108,6 +108,7 @@ bool timflg; /* Time the next waited for command */
bool havhash; /* path hashing is available */
bool filec; /* doing filename expansion */
+bool needprompt; /* print prompt, used by filec */
/*
* Global i/o info
diff --git a/bin/csh/file.c b/bin/csh/file.c
index 5d130ebf260..11c6a38a11d 100644
--- a/bin/csh/file.c
+++ b/bin/csh/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.33 2017/07/26 19:20:51 anton Exp $ */
+/* $OpenBSD: file.c,v 1.34 2017/08/30 06:42:21 anton Exp $ */
/* $NetBSD: file.c,v 1.11 1996/11/08 19:34:37 christos Exp $ */
/*-
@@ -779,8 +779,11 @@ tenex(Char *inputline, int inputline_size)
cl.size = sizeof(buf);
if (tio->c_lflag & ALTWERASE)
cl.flags |= CL_ALTWERASE;
- cl.flags |= CL_PROMPT;
- cl_flush(&cl); /* print prompt */
+ if (needprompt) {
+ needprompt = 0;
+ cl.flags |= CL_PROMPT;
+ cl_flush(&cl);
+ }
for (;;) {
if ((c = cl_getc(&cl)) == 0)
@@ -799,7 +802,14 @@ tenex(Char *inputline, int inputline_size)
for (i = 0; i < cl.len; i++)
inputline[i] = cl.buf[i];
- inputline[i] = '\0';
+ /*
+ * NUL-terminating the buffer implies that it contains a complete
+ * command ready to be executed. Therefore, don't terminate if the
+ * buffer is full since more characters must be read in order to form a
+ * complete command.
+ */
+ if (i < sizeof(buf))
+ inputline[i] = '\0';
return cl.len;
}
diff --git a/bin/csh/func.c b/bin/csh/func.c
index 4ce579d09a6..0cdcf62251b 100644
--- a/bin/csh/func.c
+++ b/bin/csh/func.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: func.c,v 1.34 2017/07/26 19:15:09 anton Exp $ */
+/* $OpenBSD: func.c,v 1.35 2017/08/30 06:42:21 anton Exp $ */
/* $NetBSD: func.c,v 1.11 1996/02/09 02:28:29 christos Exp $ */
/*-
@@ -589,7 +589,8 @@ search(int type, int level, Char *goal)
bseek(&a);
}
do {
- if (intty && !filec && fseekp == feobp && aret == F_SEEK)
+ needprompt = intty && fseekp == feobp && aret == F_SEEK;
+ if (!filec && needprompt)
(void) fprintf(cshout, "? "), (void) fflush(cshout);
aword[0] = 0;
(void) getword(aword);