From 8945f73d946a9323daf8dfc1bf5b3884cf6d7664 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Thu, 26 Jun 2014 13:30:27 +0200 Subject: Ensures that msg_controllen includes last padding. Although RFC 3542 allows both cases, Theo de Raadt thinks he knows better, and msg_controllen without last padding fails on OpenBSD. Thanks to Job Snijders for the bugreport. --- sysdep/bsd/sysio.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'sysdep/bsd/sysio.h') diff --git a/sysdep/bsd/sysio.h b/sysdep/bsd/sysio.h index fa3969bd..df5e0236 100644 --- a/sysdep/bsd/sysio.h +++ b/sysdep/bsd/sysio.h @@ -141,6 +141,7 @@ sk_prepare_cmsgs4(sock *s, struct msghdr *msg, void *cbuf, size_t cbuflen) #ifdef IP_SENDSRCADDR struct cmsghdr *cm; struct in_addr *sa; + int controllen = 0; msg->msg_control = cbuf; msg->msg_controllen = cbuflen; @@ -149,11 +150,12 @@ sk_prepare_cmsgs4(sock *s, struct msghdr *msg, void *cbuf, size_t cbuflen) cm->cmsg_level = IPPROTO_IP; cm->cmsg_type = IP_SENDSRCADDR; cm->cmsg_len = CMSG_LEN(sizeof(*sa)); + controllen += CMSG_SPACE(sizeof(*sa)); sa = (struct in_addr *) CMSG_DATA(cm); *sa = ipa_to_in4(s->saddr); - msg->msg_controllen = cm->cmsg_len; + msg->msg_controllen = controllen; #endif } -- cgit v1.2.3