diff options
author | Andreas Schneider <asn@samba.org> | 2014-06-03 15:05:12 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-06-05 23:57:10 +0200 |
commit | 3689addffbcd351e2ac0b62834b976a01c6200e0 (patch) | |
tree | b8f2e4c10f1a568ced6004cb3cc2f5ba8a6f73ba /lib/socket_wrapper | |
parent | efe4eb2385b4fbbc6f38e62082336bf39820b416 (diff) | |
download | samba-3689addffbcd351e2ac0b62834b976a01c6200e0.tar.gz samba-3689addffbcd351e2ac0b62834b976a01c6200e0.tar.xz samba-3689addffbcd351e2ac0b62834b976a01c6200e0.zip |
swrap: Call swrap_msghdr_filter_cmsghdr in swrap_sendmsg_before().
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'lib/socket_wrapper')
-rw-r--r-- | lib/socket_wrapper/socket_wrapper.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c index d1d73d9a732..c52f3d71821 100644 --- a/lib/socket_wrapper/socket_wrapper.c +++ b/lib/socket_wrapper/socket_wrapper.c @@ -3386,6 +3386,28 @@ static ssize_t swrap_sendmsg_before(int fd, return -1; } +#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL + if (msg->msg_controllen > 0 && msg->msg_control != NULL) { + uint8_t *cmbuf = NULL; + size_t cmlen = 0; + + ret = swrap_sendmsg_filter_cmsghdr(msg, cmbuf, &cmlen); + if (ret < 0) { + free(cmbuf); + return -1; + } + + if (cmlen == 0) { + msg->msg_controllen = 0; + msg->msg_control = NULL; + } else if (cmlen < msg->msg_controllen) { + memcpy(msg->msg_control, cmbuf, cmlen); + msg->msg_controllen = cmlen; + } + free(cmbuf); + } +#endif + return 0; } @@ -4133,8 +4155,15 @@ static ssize_t swrap_sendmsg(int s, const struct msghdr *omsg, int flags) msg.msg_iov = omsg->msg_iov; /* scatter/gather array */ msg.msg_iovlen = omsg->msg_iovlen; /* # elements in msg_iov */ #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL - msg.msg_control = omsg->msg_control; /* ancillary data, see below */ - msg.msg_controllen = omsg->msg_controllen; /* ancillary data buffer len */ + if (msg.msg_controllen > 0 && msg.msg_control != NULL) { + /* omsg is a const so use a local buffer for modifications */ + uint8_t cmbuf[omsg->msg_controllen]; + + memcpy(cmbuf, omsg->msg_control, omsg->msg_controllen); + + msg.msg_control = cmbuf; /* ancillary data, see below */ + msg.msg_controllen = omsg->msg_controllen; /* ancillary data buffer len */ + } msg.msg_flags = omsg->msg_flags; /* flags on received message */ #endif |