mirror of
https://github.com/tonarino/innernet.git
synced 2024-11-28 08:58:37 +02:00
netlink-request: add length check for serliazed netlink buffer
This commit is contained in:
parent
09e68c2c01
commit
4784a695ad
@ -1,5 +1,8 @@
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
mod linux {
|
mod linux {
|
||||||
|
|
||||||
|
const NETLINK_BUFFER_LENGTH: usize = 4096;
|
||||||
|
|
||||||
use netlink_packet_core::{
|
use netlink_packet_core::{
|
||||||
NetlinkDeserializable, NetlinkMessage, NetlinkPayload, NetlinkSerializable, NLM_F_ACK,
|
NetlinkDeserializable, NetlinkMessage, NetlinkPayload, NetlinkSerializable, NLM_F_ACK,
|
||||||
NLM_F_CREATE, NLM_F_EXCL, NLM_F_REQUEST,
|
NLM_F_CREATE, NLM_F_EXCL, NLM_F_REQUEST,
|
||||||
@ -78,9 +81,17 @@ mod linux {
|
|||||||
I: Clone + Debug + Eq + NetlinkSerializable + NetlinkDeserializable,
|
I: Clone + Debug + Eq + NetlinkSerializable + NetlinkDeserializable,
|
||||||
{
|
{
|
||||||
let mut req = NetlinkMessage::from(message);
|
let mut req = NetlinkMessage::from(message);
|
||||||
|
|
||||||
|
if req.buffer_len() > NETLINK_BUFFER_LENGTH {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::InvalidInput,
|
||||||
|
format!("Serialized netlink packet larger than maximum size {}", NETLINK_BUFFER_LENGTH),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
req.header.flags = flags.unwrap_or(NLM_F_REQUEST | NLM_F_ACK | NLM_F_EXCL | NLM_F_CREATE);
|
req.header.flags = flags.unwrap_or(NLM_F_REQUEST | NLM_F_ACK | NLM_F_EXCL | NLM_F_CREATE);
|
||||||
req.finalize();
|
req.finalize();
|
||||||
let mut buf = [0; 4096];
|
let mut buf = [0; NETLINK_BUFFER_LENGTH];
|
||||||
req.serialize(&mut buf);
|
req.serialize(&mut buf);
|
||||||
let len = req.buffer_len();
|
let len = req.buffer_len();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user