10
0
Fork 0
mirror of https://github.com/ZeusWPI/ZNS.git synced 2024-11-21 21:41:10 +01:00

fix wrong condition check

This commit is contained in:
Xander Bil 2024-07-28 18:23:31 +02:00
parent c213ac14f9
commit cb4812a5c5
No known key found for this signature in database
GPG key ID: EC9706B54A278598

View file

@ -158,32 +158,25 @@ impl ToBytes for LabelString {
impl FromBytes for Question { impl FromBytes for Question {
fn from_bytes(reader: &mut Reader) -> Result<Self> { fn from_bytes(reader: &mut Reader) -> Result<Self> {
// 16 for length octet + zero length octet // 16 for length octet + zero length octet
if reader.unread_bytes() < 2 + size_of::<Class>() + size_of::<Type>() { let qname = LabelString::from_bytes(reader)?;
if reader.unread_bytes() < 4 {
Err(ZNSError::Parse { Err(ZNSError::Parse {
object: String::from("Question"), object: String::from("Question"),
message: String::from("len of bytes smaller then minimum size"), message: String::from("len of rest bytes smaller then minimum size"),
}) })
} else { } else {
let qname = LabelString::from_bytes(reader)?; //Try Parse qtype
let qtype = Type::from(reader.read_u16()?);
if reader.unread_bytes() < 4 { //Try Parse qclass
Err(ZNSError::Parse { let qclass = Class::from(reader.read_u16()?);
object: String::from("Question"),
message: String::from("len of rest bytes smaller then minimum size"),
})
} else {
//Try Parse qtype
let qtype = Type::from(reader.read_u16()?);
//Try Parse qclass Ok(Question {
let qclass = Class::from(reader.read_u16()?); qname,
qtype,
Ok(Question { qclass,
qname, })
qtype,
qclass,
})
}
} }
} }
} }
@ -200,31 +193,24 @@ impl ToBytes for Question {
impl FromBytes for RR { impl FromBytes for RR {
fn from_bytes(reader: &mut Reader) -> Result<Self> { fn from_bytes(reader: &mut Reader) -> Result<Self> {
let name = LabelString::from_bytes(reader)?; let name = LabelString::from_bytes(reader)?;
if reader.unread_bytes() < size_of::<Type>() + size_of::<Class>() + 6 { let _type = Type::from(reader.read_u16()?);
let class = Class::from(reader.read_u16()?);
let ttl = reader.read_i32()?;
let rdlength = reader.read_u16()?;
if reader.unread_bytes() < rdlength as usize {
Err(ZNSError::Parse { Err(ZNSError::Parse {
object: String::from("RR"), object: String::from("RR"),
message: String::from("len of rest of bytes smaller then minimum size"), message: String::from("len of rest of bytes not equal to rdlength"),
}) })
} else { } else {
let _type = Type::from(reader.read_u16()?); Ok(RR {
let class = Class::from(reader.read_u16()?); name,
let ttl = reader.read_i32()?; _type,
let rdlength = reader.read_u16()?; class,
if reader.unread_bytes() < rdlength as usize { ttl,
Err(ZNSError::Parse { rdlength,
object: String::from("RR"), rdata: reader.read(rdlength as usize)?,
message: String::from("len of rest of bytes not equal to rdlength"), })
})
} else {
Ok(RR {
name,
_type,
class,
ttl,
rdlength,
rdata: reader.read(rdlength as usize)?,
})
}
} }
} }
} }