Sun Nov 28 12:51:12 ART 2004  Alberto Bertogli (albertogli@telpin.com.ar)
  * Limit transaction's size.
  
  Check transaction size, and don't let it grow beyond SSIZE_MAX, since
  otherwise jtrans_commit() return value could overflow and return a failure
  when there is none.
  
diff -rN -u old-libjio/common.h new-libjio/common.h
--- old-libjio/common.h	2005-03-10 15:15:10.329840984 -0300
+++ new-libjio/common.h	2004-11-28 12:41:28.000000000 -0300
@@ -26,6 +26,8 @@
 #define F_TLOCKW	(_F_TLOCK | _F_WRITE)
 #define F_UNLOCK	(_F_ULOCK)
 
+#define MAX_TSIZE	(SSIZE_MAX)
+
 
 off_t plockf(int fd, int cmd, off_t offset, off_t len);
 ssize_t spread(int fd, void *buf, size_t count, off_t offset);
diff -rN -u old-libjio/libjio.h new-libjio/libjio.h
--- old-libjio/libjio.h	2005-03-10 15:15:10.329840984 -0300
+++ new-libjio/libjio.h	2005-03-10 15:15:10.350838727 -0300
@@ -63,6 +63,7 @@
 	int id;			/* transaction id */
 	uint32_t flags;		/* transaction flags */
 	unsigned int numops;	/* quantity of operations in the list */
+	ssize_t len;		/* transaction's length */
 	pthread_mutex_t lock;	/* used to modify the operation list */
 	struct joper *op;	/* list of operations */
 };
diff -rN -u old-libjio/trans.c new-libjio/trans.c
--- old-libjio/trans.c	2005-03-10 15:15:10.328841091 -0300
+++ new-libjio/trans.c	2005-03-10 15:15:10.353838405 -0300
@@ -146,6 +146,11 @@
 		return 0;
 	}
 
+	if (ts->len + count > MAX_TSIZE) {
+		pthread_mutex_unlock(&(ts->lock));
+		return 0;
+	}
+
 	/* find the last operation in the transaction and create a new one at
 	 * the end */
 	if (ts->op == NULL) {
@@ -181,6 +186,8 @@
 		return 0;
 	}
 
+	ts->numops++;
+	ts->len += count;
 	pthread_mutex_unlock(&(ts->lock));
 
 	/* we copy the buffer because then the caller can reuse it */
@@ -192,8 +199,6 @@
 	jop->pdata = NULL;
 	jop->locked = 0;
 
-	ts->numops++;
-
 	return 1;
 }
 


