summaryrefslogtreecommitdiffhomepage
path: root/packet.c
diff options
context:
space:
mode:
authorRonny Meeus <ronny.meeus@gmail.com>2014-05-20 21:18:48 +0800
committerRonny Meeus <ronny.meeus@gmail.com>2014-05-20 21:18:48 +0800
commit0e0ff51582e5c61530715ee5e33440c6ff0b47f1 (patch)
tree40aba69ffc3b5f2796e216e04dacc0fa59c13f20 /packet.c
parentcd700aaf6e3d8f6e9eb657a242d4e5c06bacfa4d (diff)
Limit size of the iovect passed to writev in packet.c
Diffstat (limited to 'packet.c')
-rw-r--r--packet.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/packet.c b/packet.c
index dc76639..c881aab 100644
--- a/packet.c
+++ b/packet.c
@@ -64,13 +64,24 @@ void write_packet() {
struct iovec *iov = NULL;
int i;
struct Link *l;
+ int iov_max_count;
#endif
TRACE2(("enter write_packet"))
dropbear_assert(!isempty(&ses.writequeue));
#ifdef HAVE_WRITEV
- iov = m_malloc(sizeof(*iov) * ses.writequeue.count);
+
+#ifndef IOV_MAX
+#define IOV_MAX UIO_MAXIOV
+#endif
+
+ /* Make sure the size of the iov is below the maximum allowed by the OS. */
+ iov_max_count = ses.writequeue.count;
+ if (iov_max_count > IOV_MAX)
+ iov_max_count = IOV_MAX;
+
+ iov = m_malloc(sizeof(*iov) * iov_max_count);
for (l = ses.writequeue.head, i = 0; l; l = l->link, i++)
{
writebuf = (buffer*)l->item;
@@ -83,7 +94,7 @@ void write_packet() {
iov[i].iov_base = buf_getptr(writebuf, len);
iov[i].iov_len = len;
}
- written = writev(ses.sock_out, iov, ses.writequeue.count);
+ written = writev(ses.sock_out, iov, iov_max_count);
if (written < 0) {
if (errno == EINTR) {
m_free(iov);