]> granicus.if.org Git - libevent/commitdiff
Fix an EINVAL on evbuffer_write_iovec on OpenSolaris.
authorNick Mathewson <nickm@torproject.org>
Wed, 6 Oct 2010 01:34:07 +0000 (21:34 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 6 Oct 2010 14:56:49 +0000 (10:56 -0400)
The writev() call is limited to at most IOV_MAX iovecs (or UIO_MAXIOV,
depending on whom you ask).  This isn't a problem anywhere we've
tested except on OpenSolaris, where IOV_MAX was a mere 16.

This patch makes us go from "use up to 128 iovecs when writing" to
"use up to 128 iovecs when writing, or IOV_MAX/UIO_MAXIOV, whichever
is less".  This is still wrong if you somehow find a platform that
defines IOV_MAX < UIO_MAXIOV, but I hereby claim that such a platform
is too stupid to worry about for now.

Found by Michael Herf.

buffer.c

index 7d368e6f6e2e28693b1f9c1949501681bbb56a51..53a723ae489fa97c4511fefb0650957160ca95b6 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -74,6 +74,7 @@
 #ifdef _EVENT_HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#include <limits.h>
 
 #include "event2/event.h"
 #include "event2/buffer.h"
@@ -1884,7 +1885,17 @@ evbuffer_expand(struct evbuffer *buf, size_t datlen)
 #ifdef _EVENT_HAVE_SYS_UIO_H
 /* number of iovec we use for writev, fragmentation is going to determine
  * how much we end up writing */
-#define NUM_WRITE_IOVEC 128
+
+#define DEFAULT_WRITE_IOVEC 128
+
+#if defined(UIO_MAXIOV) && UIO_MAXIOV < DEFAULT_WRITE_IOVEC
+#define NUM_WRITE_IOVEC UIO_MAXIOV
+#elif defined(IOV_MAX) && IOV_MAX < DEFAULT_WRITE_IOVEC
+#define NUM_WRITE_IOVEC IOV_MAX
+#else
+#define NUM_WRITE_IOVEC DEFAULT_WRITE_IOVEC
+#endif
+
 #define IOV_TYPE struct iovec
 #define IOV_PTR_FIELD iov_base
 #define IOV_LEN_FIELD iov_len