Ver código fonte

Merge pull request #987 from thvdveld/fix-panic-when-dns

Don't panic if no valid source address is found for the DNS query
Dario Nieuwenhuis 6 meses atrás
pai
commit
dee8975afd
1 arquivos alterados com 9 adições e 1 exclusões
  1. 9 1
      src/socket/dns.rs

+ 9 - 1
src/socket/dns.rs

@@ -616,7 +616,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,