From 85fb1e6dc3c133860d8404c3b233acade91acb05 Mon Sep 17 00:00:00 2001 From: ajs Date: Thu, 11 Nov 2004 14:03:39 +0000 Subject: 2004-11-11 Andrew J. Schorr * vtysh.c: (vtysh_client_execute) Fix flaws in detecting trailing '\0' chars and command return code. --- vtysh/vtysh.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'vtysh/vtysh.c') diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index d3f672d3..c7271ff0 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -191,8 +191,11 @@ vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp) if (nbytes > 0) { + if ((numnulls == 3) && (nbytes == 1)) + return buf[0]; + buf[nbytes] = '\0'; - fprintf (fp, "%s", buf); + fputs (buf, fp); fflush (fp); /* check for trailling \0\0\0, @@ -212,18 +215,14 @@ vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp) if (buf[i++] == '\0') numnulls++; else - { - numnulls = 0; - break; - } + numnulls = 0; } - /* got 3 or more trailling nulls? */ - if (numnulls >= 3) + /* got 3 or more trailing NULs? */ + if ((numnulls >= 3) && (i < nbytes)) return (buf[nbytes-1]); } } - assert (1); } void -- cgit v1.2.1