]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
If more than one iovec then realloc the last one.
authorRoy Marples <roy@marples.name>
Fri, 2 Sep 2016 08:16:31 +0000 (08:16 +0000)
committerRoy Marples <roy@marples.name>
Fri, 2 Sep 2016 08:16:31 +0000 (08:16 +0000)
common.c

index 9b62a6a5e1357f54dd9b583ff2eb99809a4392a2..a01037053564c2e1393624ac9a1c1b156691e6c3 100644 (file)
--- a/common.c
+++ b/common.c
@@ -400,6 +400,10 @@ ssize_t
 recvmsg_realloc(int fd, struct msghdr *msg, int flags)
 {
        ssize_t bytes;
+       struct iovec *iov;
+
+       /* Assume we are reallocing the last iovec. */
+       iov = &msg->msg_iov[msg->msg_iovlen - 1];
 
        for (;;) {
                msg->msg_flags = 0;
@@ -410,14 +414,14 @@ recvmsg_realloc(int fd, struct msghdr *msg, int flags)
                        break;
 
                /* Some kernels return the truncated size. */
-               if (msg->msg_iov->iov_len == (size_t)bytes) {
+               if (iov->iov_len == (size_t)bytes) {
                        size_t nl;
 
                        nl = (size_t)roundup(bytes + 1, IOVEC_BUFSIZ);
-                       if (iovec_realloc(msg->msg_iov, nl) == NULL)
+                       if (iovec_realloc(iov, nl) == NULL)
                                return -1;
                } else {
-                       if (iovec_realloc(msg->msg_iov, (size_t)bytes) == NULL)
+                       if (iovec_realloc(iov, (size_t)bytes) == NULL)
                                return -1;
                        break;
                }