Skip to content

Conversation

@loyalpartner
Copy link

Use mem::zeroed() to initialize msghdr struct instead of struct literal
syntax, as musl libc has private padding fields (__pad1, __pad2) that
prevent direct construction. Also add type casts for msg_controllen and
cmsg_len to handle the type difference between musl (u32) and glibc
(usize).

target

- Replace manual msghdr struct initialization with mem::zeroed() for safety
- Fix type conversion for msg_controllen field from usize to libc type
- Fix type conversion for cmsg_len field in control count calculation
- Apply consistent unsafe zeroed initialization for both send and receive paths
@loyalpartner
Copy link
Author

cargo build --target=x86_64-unknown-linux-musl -p ipmb
Compiling ipmb v0.8.4 (/home/lee/tmp/ipmb/ipmb)
error: cannot construct msghdr with struct literal syntax due to private fields
--> ipmb/src/platform/linux/encoded_message.rs:45:27
|
45 | let mut hdr = libc::msghdr {
| ^^^^^^^^^^^^
|
= note: ...and other private fields __pad1 and __pad2 that were not provided

error[E0308]: mismatched types
--> ipmb/src/platform/linux/encoded_message.rs:77:34
|
77 | hdr.msg_controllen = control_data.len();
| ------------------ ^^^^^^^^^^^^^^^^^^ expected u32, found usize
| |
| expected due to the type of this binding

error[E0308]: mismatched types
--> ipmb/src/platform/linux/encoded_message.rs:98:23
|
98 | - (control_data_ptr as usize - control_ptr as usize))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u32, found usize

error[E0277]: cannot subtract usize from u32
--> ipmb/src/platform/linux/encoded_message.rs:98:21
|
98 | - (control_data_ptr as usize - control_ptr as usize))
| ^ no implementation for u32 - usize
|
= help: the trait Sub<usize> is not implemented for u32
= help: the following other types implement trait Sub<Rhs>:
&u32 implements Sub<u32>
&u32 implements Sub
u32 implements Sub<&u32>
u32 implements Sub

error[E0308]: mismatched types
--> ipmb/src/platform/linux/encoded_message.rs:99:23
|
99 | / mem::size_of::();
| ^^^^^^^^^^^^^^^^^^^^^^^ expected u32, found usize

error[E0277]: cannot divide u32 by usize
--> ipmb/src/platform/linux/encoded_message.rs:99:21
|
99 | / mem::size_of::();
| ^ no implementation for u32 / usize
|
= help: the trait Div<usize> is not implemented for u32
= help: the following other types implement trait Div<Rhs>:
&u32 implements Div<u32>
&u32 implements Div
u32 implements Div<&u32>
u32 implements Div<NonZero<u32>>
u32 implements Div

error: cannot construct msghdr with struct literal syntax due to private fields
--> ipmb/src/platform/linux/encoded_message.rs:156:23
|
156 | let mut hdr = libc::msghdr {
| ^^^^^^^^^^^^
|
= note: ...and other private fields __pad1 and __pad2 that were not provided

error[E0308]: mismatched types
--> ipmb/src/platform/linux/encoded_message.rs:171:30
|
171 | hdr.msg_controllen = self.control_data.len();
| ------------------ ^^^^^^^^^^^^^^^^^^^^^^^ expected u32, found usize
| |
| expected due to the type of this binding

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try rustc --explain E0277.
error: could not compile ipmb (lib) due to 8 previous errors
❯ cargo build --target=x86_64-unknown-linux-musl -p ipmb | wl-copy
Compiling ipmb v0.8.4 (/home/lee/tmp/ipmb/ipmb)
error: cannot construct msghdr with struct literal syntax due to private fields
--> ipmb/src/platform/linux/encoded_message.rs:45:27
|
45 | let mut hdr = libc::msghdr {
| ^^^^^^^^^^^^
|
= note: ...and other private fields __pad1 and __pad2 that were not provided

error[E0308]: mismatched types
--> ipmb/src/platform/linux/encoded_message.rs:77:34
|
77 | hdr.msg_controllen = control_data.len();
| ------------------ ^^^^^^^^^^^^^^^^^^ expected u32, found usize
| |
| expected due to the type of this binding

error[E0308]: mismatched types
--> ipmb/src/platform/linux/encoded_message.rs:98:23
|
98 | - (control_data_ptr as usize - control_ptr as usize))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u32, found usize

error[E0277]: cannot subtract usize from u32
--> ipmb/src/platform/linux/encoded_message.rs:98:21
|
98 | - (control_data_ptr as usize - control_ptr as usize))
| ^ no implementation for u32 - usize
|
= help: the trait Sub<usize> is not implemented for u32
= help: the following other types implement trait Sub<Rhs>:
&u32 implements Sub<u32>
&u32 implements Sub
u32 implements Sub<&u32>
u32 implements Sub

error[E0308]: mismatched types
--> ipmb/src/platform/linux/encoded_message.rs:99:23
|
99 | / mem::size_of::();
| ^^^^^^^^^^^^^^^^^^^^^^^ expected u32, found usize

error[E0277]: cannot divide u32 by usize
--> ipmb/src/platform/linux/encoded_message.rs:99:21
|
99 | / mem::size_of::();
| ^ no implementation for u32 / usize
|
= help: the trait Div<usize> is not implemented for u32
= help: the following other types implement trait Div<Rhs>:
&u32 implements Div<u32>
&u32 implements Div
u32 implements Div<&u32>
u32 implements Div<NonZero<u32>>
u32 implements Div

error: cannot construct msghdr with struct literal syntax due to private fields
--> ipmb/src/platform/linux/encoded_message.rs:156:23
|
156 | let mut hdr = libc::msghdr {
| ^^^^^^^^^^^^
|
= note: ...and other private fields __pad1 and __pad2 that were not provided

error[E0308]: mismatched types
--> ipmb/src/platform/linux/encoded_message.rs:171:30
|
171 | hdr.msg_controllen = self.control_data.len();
| ------------------ ^^^^^^^^^^^^^^^^^^^^^^^ expected u32, found usize
| |
| expected due to the type of this binding

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try rustc --explain E0277.
error: could not compile ipmb (lib) due to 8 previous errors
❯ cargo build --target=x86_64-unknown-linux-musl -p ipmb | wl-copy
Compiling ipmb v0.8.4 (/home/lee/tmp/ipmb/ipmb)
error: cannot construct msghdr with struct literal syntax due to private fields
--> ipmb/src/platform/linux/encoded_message.rs:45:27
|
45 | let mut hdr = libc::msghdr {
| ^^^^^^^^^^^^
|
= note: ...and other private fields __pad1 and __pad2 that were not provided

error[E0308]: mismatched types
--> ipmb/src/platform/linux/encoded_message.rs:77:34
|
77 | hdr.msg_controllen = control_data.len();
| ------------------ ^^^^^^^^^^^^^^^^^^ expected u32, found usize
| |
| expected due to the type of this binding

error[E0308]: mismatched types
--> ipmb/src/platform/linux/encoded_message.rs:98:23
|
98 | - (control_data_ptr as usize - control_ptr as usize))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u32, found usize

error[E0277]: cannot subtract usize from u32
--> ipmb/src/platform/linux/encoded_message.rs:98:21
|
98 | - (control_data_ptr as usize - control_ptr as usize))
| ^ no implementation for u32 - usize
|
= help: the trait Sub<usize> is not implemented for u32
= help: the following other types implement trait Sub<Rhs>:
&u32 implements Sub<u32>
&u32 implements Sub
u32 implements Sub<&u32>
u32 implements Sub

error[E0308]: mismatched types
--> ipmb/src/platform/linux/encoded_message.rs:99:23
|
99 | / mem::size_of::();
| ^^^^^^^^^^^^^^^^^^^^^^^ expected u32, found usize

error[E0277]: cannot divide u32 by usize
--> ipmb/src/platform/linux/encoded_message.rs:99:21
|
99 | / mem::size_of::();
| ^ no implementation for u32 / usize
|
= help: the trait Div<usize> is not implemented for u32
= help: the following other types implement trait Div<Rhs>:
&u32 implements Div<u32>
&u32 implements Div
u32 implements Div<&u32>
u32 implements Div<NonZero<u32>>
u32 implements Div

error: cannot construct msghdr with struct literal syntax due to private fields
--> ipmb/src/platform/linux/encoded_message.rs:156:23
|
156 | let mut hdr = libc::msghdr {
| ^^^^^^^^^^^^
|
= note: ...and other private fields __pad1 and __pad2 that were not provided

error[E0308]: mismatched types
--> ipmb/src/platform/linux/encoded_message.rs:171:30
|
171 | hdr.msg_controllen = self.control_data.len();
| ------------------ ^^^^^^^^^^^^^^^^^^^^^^^ expected u32, found usize
| |
| expected due to the type of this binding

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try rustc --explain E0277.
error: could not compile ipmb (lib) due to 8 previous errors

@xiaopengli89 xiaopengli89 merged commit a8562f0 into bytedance:main Dec 4, 2025
4 checks passed
@xiaopengli89
Copy link
Member

Thanks.

@loyalpartner
Copy link
Author

Hi @xiaopengli89,

Would you please update this to crates.io as soon as possible? We have a project that's actively using this library and would really appreciate having this fix available.

Thank you!

@xiaopengli89
Copy link
Member

0.8.5-20251204 has been released now.

@loyalpartner
Copy link
Author

0.8.5-20251204 has been released now.

tks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants