Pārlūkot izejas kodu

No panic if no valid src addr for DNS query

Don't panic if there is no valid source address for the DNS query. The
state of the query is set to `Failed` instead and the query is
abandoned.
Thibaut Vandervelden 6 mēneši atpakaļ
vecāks
revīzija
115fd06f03
1 mainītis faili ar 9 papildinājumiem un 1 dzēšanām
  1. 9 1
      src/socket/dns.rs

+ 9 - 1
src/socket/dns.rs

@@ -612,7 +612,15 @@ impl<'a> Socket<'a> {
                 };
 
                 let dst_addr = servers[pq.server_idx];
-                let src_addr = cx.get_source_address(&dst_addr).unwrap(); // TODO remove unwrap
+                let src_addr = match cx.get_source_address(&dst_addr) {
+                    Some(src_addr) => src_addr,
+                    None => {
+                        net_trace!("no source address for destination {}", dst_addr);
+                        q.set_state(State::Failure);
+                        continue;
+                    }
+                };
+
                 let ip_repr = IpRepr::new(
                     src_addr,
                     dst_addr,