mirror of
https://github.com/Devolutions/IronRDP.git
synced 2026-11-23 08:25:56 +00:00
fix(pdu): make AddressFamily parsing resilient (#672)
Co-authored-by: Benoît Cortier <3809077+CBenoit@users.noreply.github.com>
This commit is contained in:
@@ -754,8 +754,8 @@ fn create_client_info_pdu(config: &Config, routing_addr: &SocketAddr) -> rdp::Cl
|
||||
work_dir: String::new(),
|
||||
extra_info: ExtendedClientInfo {
|
||||
address_family: match routing_addr {
|
||||
SocketAddr::V4(_) => AddressFamily::INet,
|
||||
SocketAddr::V6(_) => AddressFamily::INet6,
|
||||
SocketAddr::V4(_) => AddressFamily::INET,
|
||||
SocketAddr::V6(_) => AddressFamily::INET_6,
|
||||
},
|
||||
address: routing_addr.ip().to_string(),
|
||||
dir: config.client_dir.clone(),
|
||||
|
||||
@@ -208,8 +208,7 @@ impl ExtendedClientInfo {
|
||||
fn decode(src: &mut ReadCursor<'_>, character_set: CharacterSet) -> DecodeResult<Self> {
|
||||
ensure_size!(in: src, size: CLIENT_ADDRESS_FAMILY_SIZE + CLIENT_ADDRESS_LENGTH_SIZE);
|
||||
|
||||
let address_family = AddressFamily::from_u16(src.read_u16())
|
||||
.ok_or_else(|| invalid_field_err!("clientAddressFamily", "invalid address family"))?;
|
||||
let address_family = AddressFamily::from_u16(src.read_u16());
|
||||
|
||||
// This size includes the length of the mandatory null terminator.
|
||||
let address_size = src.read_u16() as usize;
|
||||
@@ -235,7 +234,7 @@ impl ExtendedClientInfo {
|
||||
fn encode(&self, dst: &mut WriteCursor<'_>, character_set: CharacterSet) -> EncodeResult<()> {
|
||||
ensure_size!(in: dst, size: self.size(character_set));
|
||||
|
||||
dst.write_u16(self.address_family.to_u16().unwrap());
|
||||
dst.write_u16(self.address_family.as_u16());
|
||||
// // + size of null terminator, which will write in the write_string function
|
||||
dst.write_u16(string_len(self.address.as_str(), character_set) + character_set.to_u16().unwrap());
|
||||
utils::write_string_to_cursor(dst, self.address.as_str(), character_set, true)?;
|
||||
@@ -609,12 +608,23 @@ impl Default for PerformanceFlags {
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(u16)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive)]
|
||||
pub enum AddressFamily {
|
||||
Invalid = 0x0000, // value given by MS Remote Desktop for Android 10.0.18.1251
|
||||
INet = 0x0002,
|
||||
INet6 = 0x0017,
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct AddressFamily(u16);
|
||||
|
||||
impl AddressFamily {
|
||||
pub const INET: Self = Self(0x0002);
|
||||
pub const INET_6: Self = Self(0x0017);
|
||||
}
|
||||
|
||||
impl AddressFamily {
|
||||
pub fn from_u16(val: u16) -> Self {
|
||||
Self(val)
|
||||
}
|
||||
|
||||
pub fn as_u16(self) -> u16 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
|
||||
@@ -96,7 +96,7 @@ lazy_static::lazy_static! {
|
||||
alternate_shell: String::from(""),
|
||||
work_dir: String::from(""),
|
||||
extra_info: ExtendedClientInfo {
|
||||
address_family: AddressFamily::INet,
|
||||
address_family: AddressFamily::INET,
|
||||
address: String::from("157.59.242.156"),
|
||||
dir: String::from("C:\\depots\\w2k3_1\\termsrv\\newclient\\lib\\win32\\obj\\i386\\mstscax.dll"),
|
||||
optional_data: ExtendedClientOptionalInfo::builder()
|
||||
|
||||
Reference in New Issue
Block a user