浏览代码

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 月之前
父节点
当前提交
115fd06f03
共有 1 个文件被更改,包括 9 次插入1 次删除
  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 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(
                 let ip_repr = IpRepr::new(
                     src_addr,
                     src_addr,
                     dst_addr,
                     dst_addr,