@@ -985,6 +985,10 @@ pub const ARPHRD_IEEE802154: u16 = 804;
985985pub const ARPHRD_VOID : u16 = 0xFFFF ;
986986pub const ARPHRD_NONE : u16 = 0xFFFE ;
987987
988+ fn CMSG_ALIGN ( len : usize ) -> usize {
989+ len + mem:: size_of :: < usize > ( ) - 1 & !( mem:: size_of :: < usize > ( ) - 1 )
990+ }
991+
988992f ! {
989993 pub fn CMSG_FIRSTHDR ( mhdr: * const msghdr) -> * mut cmsghdr {
990994 if ( * mhdr) . msg_controllen as usize >= mem:: size_of:: <cmsghdr>( ) {
@@ -996,17 +1000,19 @@ f! {
9961000
9971001 pub fn CMSG_NXTHDR ( mhdr: * const msghdr,
9981002 cmsg: * const cmsghdr) -> * mut cmsghdr {
999- if cmsg. is_null ( ) {
1000- return CMSG_FIRSTHDR ( mhdr ) ;
1003+ if ( ( * cmsg) . cmsg_len as usize ) < mem :: size_of :: <cmsghdr> ( ) {
1004+ return 0 as * mut cmsghdr ;
10011005 } ;
1002- let pad = mem :: align_of :: <cmsghdr> ( ) - 1 ;
1003- let next = cmsg as usize + ( * cmsg ) . cmsg_len as usize + pad & !pad ;
1006+ let next = ( cmsg as usize + CMSG_ALIGN ( ( * cmsg ) . cmsg_len as usize ) )
1007+ as * mut cmsghdr ;
10041008 let max = ( * mhdr) . msg_control as usize
10051009 + ( * mhdr) . msg_controllen as usize ;
1006- if next < max {
1007- next as * mut cmsghdr
1008- } else {
1010+ if ( next. offset ( 1 ) ) as usize > max
1011+ || next as usize + CMSG_ALIGN ( ( * next ) . cmsg_len as usize ) > max
1012+ {
10091013 0 as * mut cmsghdr
1014+ } else {
1015+ next as * mut cmsghdr
10101016 }
10111017 }
10121018
@@ -1015,12 +1021,12 @@ f! {
10151021 }
10161022
10171023 pub fn CMSG_SPACE ( length: :: c_uint) -> :: c_uint {
1018- let pad = mem:: align_of :: <cmsghdr>( ) as :: c_uint - 1 ;
1019- mem :: size_of :: <cmsghdr> ( ) as :: c_uint + ( ( length + pad ) & !pad )
1024+ ( CMSG_ALIGN ( length as usize ) + CMSG_ALIGN ( mem:: size_of :: <cmsghdr>( ) ) )
1025+ as :: c_uint
10201026 }
10211027
10221028 pub fn CMSG_LEN ( length: :: c_uint) -> :: c_uint {
1023- mem:: size_of:: <cmsghdr>( ) as :: c_uint + length
1029+ CMSG_ALIGN ( mem:: size_of:: <cmsghdr>( ) ) as :: c_uint + length
10241030 }
10251031
10261032 pub fn FD_CLR ( fd: :: c_int, set: * mut fd_set) -> ( ) {
0 commit comments