rsync Warning: unexpected read size of 0 in map_ptr

Dave Dykstra dwd at bell-labs.com
Fri Feb 1 00:36:21 EST 2002


On Wed, Jan 30, 2002 at 06:03:10PM -0500, Bill Nottingham wrote:
> Dave Dykstra (dwd at bell-labs.com) said: 
> > I stumbled across the bug report
> >     http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=58878
> > 
> > which shows that you made a bug fix to rsync on Sunday.  What exactly did
> > you do?
> 
> Attached. It's the same thing as yours, I just added a few more comparisons &
> casts, because I was being paranoid.

Thanks.  I don't think any of those are necessary, except that there should
probably be casts to int on the rprintfs.    Casting the comparisons to
ssize_t instead of int might be a good idea if there are any systems that
have 32 bit ints and 64 bit size_t, but I don't know if there are any such
systems and there's a lot of other places where casts to int are being used
so it would be inconsistent.


> > fix I came up with is below.  Nobody even reported it to the rsync official
> > bug tracking system, although I don't believe the rsync maintainer Martin
> > Pool keeps up with responding to that very well anyway.
> 
> I sent mail to Martin and a couple other people; I haven't gotten any
> response yet. :(

Unfortunately I haven't seen any activity from Martin since he sent out the
broken release.  In the future, please post to rsync at samba.org for
important problems like this one so everybody can find out.


> Bill

- Dave Dykstra



diff -ru rsync-2.4.6/io.c rsync-2.4.6-fixed/io.c
--- rsync-2.4.6/io.c	Mon Jan 28 19:16:47 2002
+++ rsync-2.4.6-fixed/io.c	Mon Jan 28 19:15:05 2002
@@ -275,7 +275,7 @@
 
 	while (ret == 0) {
 		if (remaining) {
-			len = MIN(len, remaining);
+			len = MIN((ssize_t)len, remaining);
 			read_loop(fd, buf, len);
 			remaining -= len;
 			ret = len;
@@ -453,7 +453,7 @@
 			}
 
 			if (ret <= 0) {
-				rprintf(FERROR,"erroring writing %d bytes - exiting\n", len);
+				rprintf(FERROR,"erroring writing %lu bytes - exiting\n", len);
 				exit_cleanup(RERR_STREAMIO);
 			}
 
@@ -561,7 +561,7 @@
 	}
 
 	while (len) {
-		int n = MIN(len, IO_BUFFER_SIZE-io_buffer_count);
+		int n = MIN((ssize_t)len, IO_BUFFER_SIZE-io_buffer_count);
 		if (n > 0) {
 			memcpy(io_buffer+io_buffer_count, buf, n);
 			buf += n;
diff -ru rsync-2.4.6/match.c rsync-2.4.6-fixed/match.c
--- rsync-2.4.6/match.c	Sat Jan 29 06:35:03 2000
+++ rsync-2.4.6-fixed/match.c	Mon Jan 28 19:07:54 2002
@@ -141,9 +141,9 @@
 	last_i = -1;
 
 	if (verbose > 2)
-		rprintf(FINFO,"hash search b=%d len=%.0f\n",s->n,(double)len);
+		rprintf(FINFO,"hash search b=%lu len=%.0f\n",s->n,(double)len);
 
-	k = MIN(len, s->n);
+	k = MIN(len, (ssize_t)s->n);
 	
 	map = (schar *)map_ptr(buf,0,k);
 	
@@ -158,7 +158,7 @@
 	end = len + 1 - s->sums[s->count-1].len;
 	
 	if (verbose > 3)
-		rprintf(FINFO,"hash search s->n=%d len=%.0f count=%d\n",
+		rprintf(FINFO,"hash search s->n=%lu len=%.0f count=%lu\n",
 			s->n,(double)len,s->count);
 	
 	do {
@@ -175,13 +175,13 @@
 
 		sum = (s1 & 0xffff) | (s2 << 16);
 		tag_hits++;
-		for (; j<s->count && targets[j].t == t; j++) {
+		for (; j<(ssize_t)s->count && targets[j].t == t; j++) {
 			int l, i = targets[j].i;
 			
 			if (sum != s->sums[i].sum1) continue;
 			
 			/* also make sure the two blocks are the same length */
-			l = MIN(s->n,len-offset);
+			l = MIN((ssize_t)s->n,len-offset);
 			if (l != s->sums[i].len) continue;			
 
 			if (verbose > 3)
@@ -201,7 +201,7 @@
 
 			/* we've found a match, but now check to see
                            if last_i can hint at a better match */
-			for (j++; j<s->count && targets[j].t == t; j++) {
+			for (j++; j<(ssize_t)s->count && targets[j].t == t; j++) {
 				int i2 = targets[j].i;
 				if (i2 == last_i + 1) {
 					if (sum != s->sums[i2].sum1) break;
@@ -217,7 +217,7 @@
 			
 			matched(f,s,buf,offset,i);
 			offset += s->sums[i].len - 1;
-			k = MIN((len-offset), s->n);
+			k = MIN((len-offset), (ssize_t)s->n);
 			map = (schar *)map_ptr(buf,offset,k);
 			sum = get_checksum1((char *)map, k);
 			s1 = sum & 0xFFFF;
@@ -246,7 +246,7 @@
 		   match. The 3 reads are caused by the
 		   running match, the checksum update and the
 		   literal send. */
-		if (offset-last_match >= CHUNK_SIZE+s->n && 
+		if (offset-last_match >= (ssize_t)(CHUNK_SIZE+s->n) && 
 		    (end-offset > CHUNK_SIZE)) {
 			matched(f,s,buf,offset - s->n, -2);
 		}
diff -ru rsync-2.4.6/receiver.c rsync-2.4.6-fixed/receiver.c
--- rsync-2.4.6/receiver.c	Mon Jan 28 19:16:47 2002
+++ rsync-2.4.6-fixed/receiver.c	Mon Jan 28 19:10:02 2002
@@ -247,7 +247,7 @@
 		i = -(i+1);
 		offset2 = i*(OFF_T)n;
 		len = n;
-		if (i == count-1 && remainder != 0)
+		if (i == (int)(count-1) && remainder != 0)
 			len = remainder;
 		
 		stats.matched_data += len;
@@ -263,7 +263,7 @@
 			sum_update(map,len);
 		}
 		
-		if (fd != -1 && write_file(fd,map,len) != len) {
+		if (fd != -1 && write_file(fd,map,len) != (int)len) {
 			rprintf(FERROR,"write failed on %s : %s\n",
 				fname,strerror(errno));
 			exit_cleanup(RERR_FILEIO);
diff -ru rsync-2.4.6/sender.c rsync-2.4.6-fixed/sender.c
--- rsync-2.4.6/sender.c	Tue Sep  5 22:46:43 2000
+++ rsync-2.4.6-fixed/sender.c	Mon Jan 28 19:11:21 2002
@@ -46,7 +46,7 @@
 	s->sums = NULL;
 
 	if (verbose > 3)
-		rprintf(FINFO,"count=%d n=%d rem=%d\n",
+		rprintf(FINFO,"count=%lu n=%lu rem=%lu\n",
 			s->count,s->n,s->remainder);
 
 	if (s->count == 0) 





More information about the rsync mailing list