[quagga-dev 1464] vtysh sync bug

Paul Jakma paul at clubi.ie
Sun Sep 12 03:20:02 BST 2004


vtysh has a fun little bug, it looks for \0\0\0\0 as sort of 'EOF' in 
command output from daemons, however it only expects these to happen 
at end of a read, or at beginning.

This can create fun if command output is length x, where 996 < x < 
1000 - the nulls will be split across reads, and vtysh blocks 
forever.

the attached patch hopefully should fix it.

regards,
-- 
Paul Jakma	paul at clubi.ie	paul at jakma.org	Key ID: 64A2FF6A
Fortune:
Sanity and insanity overlap a fine grey line.
-------------- next part --------------
? vtyd_main.c
Index: vtysh.c
===================================================================
RCS file: /var/cvsroot/quagga/vtysh/vtysh.c,v
retrieving revision 1.27
diff -u -r1.27 vtysh.c
--- vtysh.c	27 Aug 2004 14:23:28 -0000	1.27
+++ vtysh.c	9 Sep 2004 00:39:55 -0000
@@ -160,7 +160,8 @@
   int ret;
   char buf[1001];
   int nbytes;
-  int i;
+  int i; 
+  int numnulls = 0;
 
   if (vclient->fd < 0)
     return CMD_SUCCESS;
@@ -187,16 +188,18 @@
 	  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 */
+          i = nbytes;
+          while ( i > 0 && ((nbytes - i) < 4) 
+                 && (buf[i] == '\0') )
+            i--;
+          
+          /* got 3 or more trailling nulls? */
+          if ( (numnulls + (nbytes - i)) >= 3)
+            return '\0';
+          else
+            numnulls = nbytes - i;
 	}
     }
   return ret;


More information about the Quagga-dev mailing list