mirror of
https://git.openafs.org/openafs.git
synced 2025-01-31 13:38:01 +00:00
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:
parent
12ce31ce1d
commit
af58c5cd15
@ -108,11 +108,11 @@ osi_HandleSocketError(osi_socket so, void *cmsgbuf, size_t cmsgbuf_len)
|
|||||||
int code;
|
int code;
|
||||||
struct socket *sop = (struct socket *)so;
|
struct socket *sop = (struct socket *)so;
|
||||||
|
|
||||||
|
memset(&msg, 0, sizeof(msg));
|
||||||
msg.msg_name = &addr;
|
msg.msg_name = &addr;
|
||||||
msg.msg_namelen = sizeof(addr);
|
msg.msg_namelen = sizeof(addr);
|
||||||
msg.msg_control = cmsgbuf;
|
msg.msg_control = cmsgbuf;
|
||||||
msg.msg_controllen = cmsgbuf_len;
|
msg.msg_controllen = cmsgbuf_len;
|
||||||
msg.msg_flags = 0;
|
|
||||||
|
|
||||||
code = kernel_recvmsg(sop, &msg, NULL, 0, 0,
|
code = kernel_recvmsg(sop, &msg, NULL, 0, 0,
|
||||||
MSG_ERRQUEUE|MSG_DONTWAIT|MSG_TRUNC);
|
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;
|
struct msghdr msg;
|
||||||
int code;
|
int code;
|
||||||
|
|
||||||
|
memset(&msg, 0, sizeof(msg));
|
||||||
msg.msg_name = to;
|
msg.msg_name = to;
|
||||||
msg.msg_namelen = sizeof(*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);
|
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));
|
memcpy(tmpvec, iov, iovcnt * sizeof(struct iovec));
|
||||||
|
memset(&msg, 0, sizeof(msg));
|
||||||
msg.msg_name = from;
|
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,
|
code = kernel_recvmsg(sop, &msg, (struct kvec *)tmpvec, iovcnt,
|
||||||
*lengthp, 0);
|
*lengthp, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user