Linux: Clear msghdr structure before use

The msghdr structure is used as a parameter to the Linux kernel
functions kernel_sendmsg() and kernel_recvmsg(). Some required fields
need to be set prior to calling these functions, but there are also
additional structure members that may not be used by the calling code.
Some of these fields may be initialized by the Linux kernel functions
being used, but there may be some that are left uninitialized.

To ensure that all fields in the msghdr structure are cleared, use
memset to zero the entire structure. This will eliminate the need to set
individual fields to 0 or NULL.

Reviewed-on: https://gerrit.openafs.org/15409
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
(cherry picked from commit 795ef90d4041f1a5a1139435cc70f96457e0f64b)

Change-Id: Id037e2e548c27b23e2746f804ddcaf7b79d905c4
Reviewed-on: https://gerrit.openafs.org/15411
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
This commit is contained in:
Cheyenne Wills 2023-04-27 09:49:03 -06:00 committed by Stephan Wiesand
parent 12ce31ce1d
commit af58c5cd15

View File

@ -108,11 +108,11 @@ osi_HandleSocketError(osi_socket so, void *cmsgbuf, size_t cmsgbuf_len)
int code;
struct socket *sop = (struct socket *)so;
memset(&msg, 0, sizeof(msg));
msg.msg_name = &addr;
msg.msg_namelen = sizeof(addr);
msg.msg_control = cmsgbuf;
msg.msg_controllen = cmsgbuf_len;
msg.msg_flags = 0;
code = kernel_recvmsg(sop, &msg, NULL, 0, 0,
MSG_ERRQUEUE|MSG_DONTWAIT|MSG_TRUNC);
@ -153,12 +153,9 @@ osi_NetSend(osi_socket sop, struct sockaddr_in *to, struct iovec *iovec,
struct msghdr msg;
int code;
memset(&msg, 0, sizeof(msg));
msg.msg_name = to;
msg.msg_namelen = sizeof(*to);
msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = 0;
code = kernel_sendmsg(sop, &msg, (struct kvec *) iovec, iovcnt, size);
@ -201,10 +198,8 @@ osi_NetReceive(osi_socket so, struct sockaddr_in *from, struct iovec *iov,
}
memcpy(tmpvec, iov, iovcnt * sizeof(struct iovec));
memset(&msg, 0, sizeof(msg));
msg.msg_name = from;
msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = 0;
code = kernel_recvmsg(sop, &msg, (struct kvec *)tmpvec, iovcnt,
*lengthp, 0);