Rollup merge of #43821 - NilSet:redox-dns, r=alexcrichton
Handle DNS label compression in more places in Redox name resolution
This commit is contained in:
commit
b1a742794e
@ -102,6 +102,7 @@ macro_rules! push_n16 {
|
||||
}
|
||||
|
||||
pub fn parse(data: &[u8]) -> Result<Self, String> {
|
||||
let name_ind = 0b11000000;
|
||||
let mut i = 0;
|
||||
|
||||
macro_rules! pop_u8 {
|
||||
@ -147,9 +148,15 @@ macro_rules! pop_name {
|
||||
() => {
|
||||
{
|
||||
let mut name = String::new();
|
||||
let old_i = i;
|
||||
|
||||
loop {
|
||||
let name_len = pop_u8!();
|
||||
if name_len & name_ind == name_ind {
|
||||
i -= 1;
|
||||
i = (pop_n16!() - ((name_ind as u16) << 8)) as usize;
|
||||
continue;
|
||||
}
|
||||
if name_len == 0 {
|
||||
break;
|
||||
}
|
||||
@ -161,6 +168,10 @@ macro_rules! pop_name {
|
||||
}
|
||||
}
|
||||
|
||||
if i <= old_i {
|
||||
i = old_i + 2;
|
||||
}
|
||||
|
||||
name
|
||||
}
|
||||
};
|
||||
@ -184,21 +195,8 @@ macro_rules! pop_name {
|
||||
|
||||
let mut answers = Vec::new();
|
||||
for _answer_i in 0..answers_len {
|
||||
let name_ind = 0b11000000;
|
||||
let name_test = pop_u8!();
|
||||
i -= 1;
|
||||
|
||||
answers.push(DnsAnswer {
|
||||
name: if name_test & name_ind == name_ind {
|
||||
let name_off = pop_n16!() - ((name_ind as u16) << 8);
|
||||
let old_i = i;
|
||||
i = name_off as usize;
|
||||
let name = pop_name!();
|
||||
i = old_i;
|
||||
name
|
||||
} else {
|
||||
pop_name!()
|
||||
},
|
||||
name: pop_name!(),
|
||||
a_type: pop_n16!(),
|
||||
a_class: pop_n16!(),
|
||||
ttl_a: pop_n16!(),
|
||||
|
Loading…
Reference in New Issue
Block a user