Skip to content

Handle DNS label compression in more places in Redox name resolution #43821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/libstd/sys/redox/net/dns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl Dns {
}

pub fn parse(data: &[u8]) -> Result<Self, String> {
let name_ind = 0b11000000;
let mut i = 0;

macro_rules! pop_u8 {
Expand Down Expand Up @@ -147,9 +148,15 @@ impl Dns {
() => {
{
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;
}
Expand All @@ -161,6 +168,10 @@ impl Dns {
}
}

if i <= old_i {
i = old_i + 2;
}

name
}
};
Expand All @@ -184,21 +195,8 @@ impl Dns {

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!(),
Expand Down