@@ -985,6 +985,10 @@ pub const ARPHRD_IEEE802154: u16 = 804;
985
985
pub const ARPHRD_VOID : u16 = 0xFFFF ;
986
986
pub const ARPHRD_NONE : u16 = 0xFFFE ;
987
987
988
+ fn CMSG_ALIGN ( len : usize ) -> usize {
989
+ len + mem:: size_of :: < usize > ( ) - 1 & !( mem:: size_of :: < usize > ( ) - 1 )
990
+ }
991
+
988
992
f ! {
989
993
pub fn CMSG_FIRSTHDR ( mhdr: * const msghdr) -> * mut cmsghdr {
990
994
if ( * mhdr) . msg_controllen as usize >= mem:: size_of:: <cmsghdr>( ) {
@@ -996,17 +1000,19 @@ f! {
996
1000
997
1001
pub fn CMSG_NXTHDR ( mhdr: * const msghdr,
998
1002
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 ;
1001
1005
} ;
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 ;
1004
1008
let max = ( * mhdr) . msg_control as usize
1005
1009
+ ( * 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
+ {
1009
1013
0 as * mut cmsghdr
1014
+ } else {
1015
+ next as * mut cmsghdr
1010
1016
}
1011
1017
}
1012
1018
@@ -1015,12 +1021,12 @@ f! {
1015
1021
}
1016
1022
1017
1023
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
1020
1026
}
1021
1027
1022
1028
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
1024
1030
}
1025
1031
1026
1032
pub fn FD_CLR ( fd: :: c_int, set: * mut fd_set) -> ( ) {
0 commit comments