summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2014-05-23 14:35:59 +0200
committerAndreas Schneider <asn@samba.org>2014-05-26 16:45:16 +0200
commit27be91da8fbb56826c361abd67ebb1e081540bfe (patch)
tree43cac539d3085f5c9fde74ca827d79f4e49a7245 /src
parent4849b2ebbfca6176e685ac9c6c933aad8470295f (diff)
downloadsocket_wrapper-27be91da8fbb56826c361abd67ebb1e081540bfe.tar.gz
socket_wrapper-27be91da8fbb56826c361abd67ebb1e081540bfe.tar.xz
socket_wrapper-27be91da8fbb56826c361abd67ebb1e081540bfe.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 'src')
-rw-r--r--src/socket_wrapper.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index d1d73d9..c52f3d7 100644
--- a/src/socket_wrapper.c
+++ b/src/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