Mercurial > dropbear
comparison packet.c @ 933:c919dbb39395
Limit size of the iovect passed to writev in packet.c
author | Ronny Meeus <ronny.meeus@gmail.com> |
---|---|
date | Tue, 20 May 2014 21:18:48 +0800 |
parents | 3873b39c4de6 |
children | 68723d66dec6 |
comparison
equal
deleted
inserted
replaced
932:3873b39c4de6 | 933:c919dbb39395 |
---|---|
62 int all_ignore = 1; | 62 int all_ignore = 1; |
63 #ifdef HAVE_WRITEV | 63 #ifdef HAVE_WRITEV |
64 struct iovec *iov = NULL; | 64 struct iovec *iov = NULL; |
65 int i; | 65 int i; |
66 struct Link *l; | 66 struct Link *l; |
67 int iov_max_count; | |
67 #endif | 68 #endif |
68 | 69 |
69 TRACE2(("enter write_packet")) | 70 TRACE2(("enter write_packet")) |
70 dropbear_assert(!isempty(&ses.writequeue)); | 71 dropbear_assert(!isempty(&ses.writequeue)); |
71 | 72 |
72 #ifdef HAVE_WRITEV | 73 #ifdef HAVE_WRITEV |
73 iov = m_malloc(sizeof(*iov) * ses.writequeue.count); | 74 |
75 #ifndef IOV_MAX | |
76 #define IOV_MAX UIO_MAXIOV | |
77 #endif | |
78 | |
79 /* Make sure the size of the iov is below the maximum allowed by the OS. */ | |
80 iov_max_count = ses.writequeue.count; | |
81 if (iov_max_count > IOV_MAX) | |
82 iov_max_count = IOV_MAX; | |
83 | |
84 iov = m_malloc(sizeof(*iov) * iov_max_count); | |
74 for (l = ses.writequeue.head, i = 0; l; l = l->link, i++) | 85 for (l = ses.writequeue.head, i = 0; l; l = l->link, i++) |
75 { | 86 { |
76 writebuf = (buffer*)l->item; | 87 writebuf = (buffer*)l->item; |
77 packet_type = writebuf->data[writebuf->len-1]; | 88 packet_type = writebuf->data[writebuf->len-1]; |
78 len = writebuf->len - 1 - writebuf->pos; | 89 len = writebuf->len - 1 - writebuf->pos; |
81 TRACE2(("write_packet writev #%d type %d len %d/%d", i, packet_type, | 92 TRACE2(("write_packet writev #%d type %d len %d/%d", i, packet_type, |
82 len, writebuf->len-1)) | 93 len, writebuf->len-1)) |
83 iov[i].iov_base = buf_getptr(writebuf, len); | 94 iov[i].iov_base = buf_getptr(writebuf, len); |
84 iov[i].iov_len = len; | 95 iov[i].iov_len = len; |
85 } | 96 } |
86 written = writev(ses.sock_out, iov, ses.writequeue.count); | 97 written = writev(ses.sock_out, iov, iov_max_count); |
87 if (written < 0) { | 98 if (written < 0) { |
88 if (errno == EINTR) { | 99 if (errno == EINTR) { |
89 m_free(iov); | 100 m_free(iov); |
90 TRACE2(("leave write_packet: EINTR")) | 101 TRACE2(("leave write_packet: EINTR")) |
91 return; | 102 return; |