summaryrefslogtreecommitdiffstats
path: root/lib/vty.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-01-18 07:09:26 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2017-01-18 17:15:12 +0100
commit88e5a8cbe199c33039108c0d1d41790438f96235 (patch)
treeeaa6e4fb3cc3bc9446e7fa1e0d07ced3ddb5b7be /lib/vty.c
parentMerge pull request #78 from pguibert6WIND/fix_str2prefix_rd_as4 (diff)
downloadfrr-88e5a8cbe199c33039108c0d1d41790438f96235.tar.xz
frr-88e5a8cbe199c33039108c0d1d41790438f96235.zip
lib: additional patch for 496e83a
Fixes a couple off-by-ones introduced in previous commit. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com> [cherry-picked from master d1e4a518e6f55ccf80c67b58d16eeb1cbf5923e3] Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to '')
-rw-r--r--lib/vty.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/vty.c b/lib/vty.c
index 23d715341..adcfaca4f 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -515,7 +515,7 @@ vty_self_insert (struct vty *vty, char c)
int i;
int length;
- if (vty->length + 1 > VTY_BUFSIZ)
+ if (vty->length + 1 >= VTY_BUFSIZ)
return;
length = vty->length - vty->cp;
@@ -528,6 +528,8 @@ vty_self_insert (struct vty *vty, char c)
vty->cp++;
vty->length++;
+
+ vty->buf[vty->length] = '\0';
}
/* Self insert character 'c' in overwrite mode. */
@@ -553,11 +555,15 @@ vty_self_insert_overwrite (struct vty *vty, char c)
static void
vty_insert_word_overwrite (struct vty *vty, char *str)
{
- size_t nwrite = MIN ((int) strlen (str), VTY_BUFSIZ - vty->cp);
- vty_write (vty, str, nwrite);
- strncpy (&vty->buf[vty->cp], str, nwrite);
+ if (vty->cp == VTY_BUFSIZ)
+ return;
+
+ size_t nwrite = MIN ((int) strlen (str), VTY_BUFSIZ - vty->cp - 1);
+ memcpy (&vty->buf[vty->cp], str, nwrite);
vty->cp += nwrite;
- vty->length = vty->cp;
+ vty->length = MAX (vty->cp, vty->length);
+ vty->buf[vty->length] = '\0';
+ vty_write (vty, str, nwrite);
}
/* Forward character. */
@@ -614,6 +620,7 @@ vty_history_print (struct vty *vty)
length = strlen (vty->hist[vty->hp]);
memcpy (vty->buf, vty->hist[vty->hp], length);
vty->cp = vty->length = length;
+ vty->buf[vty->length] = '\0';
/* Redraw current line */
vty_redraw_line (vty);
@@ -2210,7 +2217,7 @@ vtysh_read (struct thread *thread)
printf ("line: %.*s\n", nbytes, buf);
#endif /* VTYSH_DEBUG */
- if (vty->length + nbytes > VTY_BUFSIZ)
+ if (vty->length + nbytes >= VTY_BUFSIZ)
{
/* Clear command line buffer. */
vty->cp = vty->length = 0;