@@ -1114,6 +1114,10 @@ pub const ARPHRD_IEEE802154: u16 = 804;
1114
1114
pub const ARPHRD_VOID : u16 = 0xFFFF ;
1115
1115
pub const ARPHRD_NONE : u16 = 0xFFFE ;
1116
1116
1117
+ fn CMSG_ALIGN ( len : usize ) -> usize {
1118
+ len + mem:: size_of :: < usize > ( ) - 1 & !( mem:: size_of :: < usize > ( ) - 1 )
1119
+ }
1120
+
1117
1121
f ! {
1118
1122
pub fn CMSG_FIRSTHDR ( mhdr: * const msghdr) -> * mut cmsghdr {
1119
1123
if ( * mhdr) . msg_controllen as usize >= mem:: size_of:: <cmsghdr>( ) {
@@ -1125,17 +1129,19 @@ f! {
1125
1129
1126
1130
pub fn CMSG_NXTHDR ( mhdr: * const msghdr,
1127
1131
cmsg: * const cmsghdr) -> * mut cmsghdr {
1128
- if cmsg. is_null ( ) {
1129
- return CMSG_FIRSTHDR ( mhdr ) ;
1132
+ if ( ( * cmsg) . cmsg_len as usize ) < mem :: size_of :: <cmsghdr> ( ) {
1133
+ return 0 as * mut cmsghdr ;
1130
1134
} ;
1131
- let pad = mem :: align_of :: <cmsghdr> ( ) - 1 ;
1132
- let next = cmsg as usize + ( * cmsg ) . cmsg_len as usize + pad & !pad ;
1135
+ let next = ( cmsg as usize + CMSG_ALIGN ( ( * cmsg ) . cmsg_len as usize ) )
1136
+ as * mut cmsghdr ;
1133
1137
let max = ( * mhdr) . msg_control as usize
1134
1138
+ ( * mhdr) . msg_controllen as usize ;
1135
- if next < max {
1136
- next as * mut cmsghdr
1137
- } else {
1139
+ if ( next. offset ( 1 ) ) as usize > max
1140
+ || next as usize + CMSG_ALIGN ( ( * next ) . cmsg_len as usize ) > max
1141
+ {
1138
1142
0 as * mut cmsghdr
1143
+ } else {
1144
+ next as * mut cmsghdr
1139
1145
}
1140
1146
}
1141
1147
@@ -1144,12 +1150,12 @@ f! {
1144
1150
}
1145
1151
1146
1152
pub fn CMSG_SPACE ( length: :: c_uint) -> :: c_uint {
1147
- let pad = mem:: align_of :: <cmsghdr>( ) as :: c_uint - 1 ;
1148
- mem :: size_of :: <cmsghdr> ( ) as :: c_uint + ( ( length + pad ) & !pad )
1153
+ ( CMSG_ALIGN ( length as usize ) + CMSG_ALIGN ( mem:: size_of :: <cmsghdr>( ) ) )
1154
+ as :: c_uint
1149
1155
}
1150
1156
1151
1157
pub fn CMSG_LEN ( length: :: c_uint) -> :: c_uint {
1152
- mem:: size_of:: <cmsghdr>( ) as :: c_uint + length
1158
+ CMSG_ALIGN ( mem:: size_of:: <cmsghdr>( ) ) as :: c_uint + length
1153
1159
}
1154
1160
1155
1161
pub fn FD_CLR ( fd: :: c_int, set: * mut fd_set) -> ( ) {
0 commit comments