swrap: don't touch msg_tmp in swrap_recvmsg_after_unix() on error
authorStefan Metzmacher <metze@samba.org>
Tue, 9 Feb 2021 15:09:59 +0000 (16:09 +0100)
committerAndreas Schneider <asn@samba.org>
Tue, 9 Feb 2021 15:53:48 +0000 (16:53 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
src/socket_wrapper.c

index 6a63530ba7ac72f13b4d2ac6654574606afb3735..59fb07dc5909274633927440190e46038c740392 100644 (file)
@@ -6021,6 +6021,16 @@ static ssize_t swrap_recvmsg_after_unix(struct msghdr *msg_tmp,
        size_t cm_data_space = 0;
        int rc = -1;
 
+       if (ret < 0) {
+               int saved_errno = errno;
+               SWRAP_LOG(SWRAP_LOG_TRACE, "ret=%zd - %d - %s", ret,
+                         saved_errno, strerror(saved_errno));
+               SAFE_FREE(*tmp_control);
+               /* msg_out should not be touched on error */
+               errno = saved_errno;
+               return ret;
+       }
+
        SWRAP_LOG(SWRAP_LOG_TRACE,
                  "msg_tmp->msg_controllen=%zu",
                  (size_t)msg_tmp->msg_controllen);