From: David Lamparter Date: Fri, 12 Feb 2021 22:30:55 +0000 (+0100) Subject: lib: fix CRNL causing empty prompt lines X-Git-Tag: base_8.0~388^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=e0a5979d58c39b6a173052867f4f44e9b85bd1c3;p=matthieu%2Ffrr.git 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 --- diff --git a/lib/vty.c b/lib/vty.c index 2a71547884..65f8d78a96 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);