summaryrefslogtreecommitdiffstats
path: root/lib/vty.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2021-02-12 23:30:55 +0100
committerDavid Lamparter <equinox@diac24.net>2021-02-15 01:29:44 +0100
commite0a5979d58c39b6a173052867f4f44e9b85bd1c3 (patch)
tree58963713ed08a5ad6711ef5b1dd28f9f85b03860 /lib/vty.c
parentlib: stop parallel-passing vty_sock, detangle (diff)
downloadfrr-e0a5979d58c39b6a173052867f4f44e9b85bd1c3.tar.xz
frr-e0a5979d58c39b6a173052867f4f44e9b85bd1c3.zip
lib: fix CRNL causing empty prompt lines
CR, NL and CRNL are all OK, but CRNL shouldn't get treated as 2 newlines (which causes an empty command to be executed => empty prompt line.) Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to '')
-rw-r--r--lib/vty.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/vty.c b/lib/vty.c
index 2a7154788..65f8d78a9 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -1285,6 +1285,7 @@ static int vty_execute(struct vty *vty)
#define VTY_NORMAL 0
#define VTY_PRE_ESCAPE 1
#define VTY_ESCAPE 2
+#define VTY_CR 3
/* Escape character command map. */
static void vty_escape_map(unsigned char c, struct vty *vty)
@@ -1423,6 +1424,17 @@ static int vty_read(struct thread *thread)
continue;
}
+ if (vty->escape == VTY_CR) {
+ /* if we get CR+NL, the NL results in an extra empty
+ * prompt line being printed without this; just drop
+ * the NL if it immediately follows CR.
+ */
+ vty->escape = VTY_NORMAL;
+
+ if (buf[i] == '\n')
+ continue;
+ }
+
switch (buf[i]) {
case CONTROL('A'):
vty_beginning_of_line(vty);
@@ -1467,8 +1479,10 @@ static int vty_read(struct thread *thread)
case CONTROL('Z'):
vty_end_config(vty);
break;
- case '\n':
case '\r':
+ vty->escape = VTY_CR;
+ /* fallthru */
+ case '\n':
vty_out(vty, "\n");
buffer_flush_available(vty->obuf, vty->wfd);
vty_execute(vty);