Bladeren bron

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 maanden geleden
bovenliggende
commit
115fd06f03
1 gewijzigde bestanden met toevoegingen van 9 en 1 verwijderingen
  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,