Ethereal-users: Re: [Ethereal-users] rsync protocol: probably a dumb question...

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Fri, 8 Aug 2003 02:06:11 -0700
On Fri, Aug 08, 2003 at 09:48:23AM +0100, Alan Burlison wrote:
> Guy Harris wrote:
> 
> > There was a bug when a zero-length string appeared in some packets; I've
> > checked in a fix.
> 
> Thanks :-)

I've attached a patch, for those who've compiled Ethereal, but not from
CVS.

Index: epan/tvbuff.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/epan/tvbuff.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -c -r1.47 -r1.48
*** epan/tvbuff.c	12 Jun 2003 08:33:31 -0000	1.47
--- epan/tvbuff.c	8 Aug 2003 08:19:50 -0000	1.48
***************
*** 1746,1751 ****
--- 1746,1753 ----
   * truncated in the buffer due to not having reached the terminating NUL.
   * In this way, it acts like snprintf().
   *
+  * bufsize MUST be greater than 0.
+  *
   * When processing a packet where the remaining number of bytes is less
   * than bufsize, an exception is not thrown if the end of the packet
   * is reached before the NUL is found. If no NUL is found before reaching
***************
*** 1767,1776 ****
  
  	check_offset_length(tvb, offset, 0, &abs_offset, &junk_length);
  
! 	if (bufsize == 0) {
! 		*bytes_copied = 0;
! 		return -1;
! 	} else if (bufsize == 1) {
  		buffer[0] = 0;
  		*bytes_copied = 1;
  		return 0;
--- 1769,1779 ----
  
  	check_offset_length(tvb, offset, 0, &abs_offset, &junk_length);
  
! 	/* There must at least be room for the terminating NUL. */
! 	g_assert(bufsize != 0);
! 
! 	/* If there's no room for anything else, just return the NUL. */
! 	if (bufsize == 1) {
  		buffer[0] = 0;
  		*bytes_copied = 1;
  		return 0;
***************
*** 1850,1857 ****
  /* Like tvb_get_nstringz(), but never returns -1. The string is guaranteed to
   * have a terminating NUL. If the string was truncated when copied into buffer,
   * a NUL is placed at the end of buffer to terminate it.
-  *
-  * bufsize MUST be greater than 0.
   */
  gint
  tvb_get_nstringz0(tvbuff_t *tvb, gint offset, guint bufsize, guint8* buffer)
--- 1853,1858 ----
***************
*** 1859,1868 ****
  	gint	len, bytes_copied;
  
  	len = _tvb_get_nstringz(tvb, offset, bufsize, buffer, &bytes_copied);
- 
- 	if (len == 0) {
- 		THROW(BoundsError);
- 	}
  
  	if (len == -1) {
  		buffer[bufsize - 1] = 0;
--- 1860,1865 ----