vadorovsky / network-types

Rust structs representing network-related types (on Layer 2, 3 and 4)
https://crates.io/crates/network-types
MIT License
43 stars 13 forks source link

Undefined behavior when EtherType or IP protocol number don't match any enum descriminant #22

Open arctic-alpaca opened 1 month ago

arctic-alpaca commented 1 month ago

Hey,

if the EtherType or the IP protocol number don't match any of the defined discriminants in their respective enums, the behavior is undefined.

According to https://doc.rust-lang.org/reference/behavior-considered-undefined.html, producing an a discriminant in an enum not included in the type definition is undefined.

This could be fixed by replacing the enum with the corresponding integer and adding a TryFrom to the enum implementation.

Toorero commented 1 month ago

The replacement of IpProto and EtherType with their discriminats in structs would also allow to use zerocopy to actually make the crate safe to use