Explorar o código

Fix from mark and daniel for small packet sizes in totempg resulting
in segfault.

(Logical change 1.125)


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@441 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake %!s(int64=21) %!d(string=hai) anos
pai
achega
e6a0eca16a
Modificáronse 1 ficheiros con 12 adicións e 2 borrados
  1. 12 2
      exec/totempg.c

+ 12 - 2
exec/totempg.c

@@ -92,6 +92,8 @@
 
 #include "swab.h"
 
+#define min(a,b) ((a) < (b)) ? a : b
+
 struct totempg_mcast_header {
 	short version;
 	short type;
@@ -425,6 +427,7 @@ int totempg_initialize (
 	return (res);
 }
 
+
 /*
  * Multicast a message
  */
@@ -452,8 +455,12 @@ int totempg_mcast (
 
 		/*
 		 * If it all fits with room left over, copy it in.
+		 * We need to leave at least sizeof(short) + 1 bytes in the
+		 * fragment_buffer on exit so that max_packet_size + fragment_size
+		 * doesn't exceed the size of the fragment_buffer on the next call.
 		 */
-		if ((copy_len + fragment_size) < max_packet_size) {
+		if ((copy_len + fragment_size) < 
+						(max_packet_size - sizeof (unsigned short))) {
 			memcpy (&fragmentation_data[fragment_size],
 				iovec[i].iov_base + copy_base, copy_len);
 			fragment_size += copy_len;
@@ -467,7 +474,7 @@ int totempg_mcast (
 		 * If it just fits or is too big, then send out what fits.
 		 */
 		} else {
-			copy_len = max_packet_size - fragment_size;
+			copy_len = min(copy_len, max_packet_size - fragment_size);
 			memcpy (&fragmentation_data[fragment_size],
 				iovec[i].iov_base + copy_base, copy_len);
 			mcast_packed_msg_lens[mcast_packed_msg_count] += copy_len;
@@ -542,3 +549,6 @@ int totempg_send_ok (
 
 	return (avail > 200);
 }
+/*
+ *	vi: set autoindent tabstop=4 shiftwidth=4 :
+ */