Parcourir la source

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 il y a 6 mois
Parent
commit
115fd06f03
1 fichiers modifiés avec 9 ajouts et 1 suppressions
  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,