diff options
Diffstat (limited to 'vtysh')
-rw-r--r-- | vtysh/ChangeLog | 5 | ||||
-rw-r--r-- | vtysh/vtysh.c | 37 |
2 files changed, 31 insertions, 11 deletions
diff --git a/vtysh/ChangeLog b/vtysh/ChangeLog index 54960e1a..1156afcd 100644 --- a/vtysh/ChangeLog +++ b/vtysh/ChangeLog @@ -1,3 +1,8 @@ +2004-09-17 Paul Jakma <paul@dishone.st> + + * vtysh.c: (vtysh_client_execute) trailling NULLs can be arbitrarily + split across reads, dont get confused by this and block forever. + 2004-09-13 Paul Jakma <paul@dishone.st> * Makefile.am: extract.pl isnt in srcdir, it's always in the builddir. diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 45596b29..b50424af 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -160,7 +160,8 @@ vtysh_client_execute (struct vtysh_client *vclient, char *line, FILE *fp) int ret; char buf[1001]; int nbytes; - int i; + int i; + int numnulls = 0; if (vclient->fd < 0) return CMD_SUCCESS; @@ -187,16 +188,30 @@ vtysh_client_execute (struct vtysh_client *vclient, char *line, FILE *fp) buf[nbytes] = '\0'; fprintf (fp, "%s", buf); fflush (fp); - - if (nbytes >= 4) - { - i = nbytes - 4; - if (buf[i] == '\0' && buf[i + 1] == '\0' && buf[i + 2] == '\0') - { - ret = buf[i + 3]; - break; - } - } + + /* check for trailling \0\0\0\0, even if split across reads */ + if (nbytes >= 4) + { + i = nbytes-4; + numnulls = 0; + } + else + i = 0; + + while (i < nbytes) + { + if (buf[i++] == '\0') + numnulls++; + else + { + numnulls = 0; + break; + } + } + + /* got 3 or more trailling nulls? */ + if (numnulls >= 3) + return CMD_SUCCESS; } } return ret; |