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
This commit is contained in:
Steven Dake 2005-01-31 22:07:48 +00:00
parent 09d20d5f1e
commit e6a0eca16a

View File

@ -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 :
*/