Browse Source

Merge pull request #2472 from Kelimion/resolv_fix

Fix #2471
Jeroen van Rijn 2 years ago
parent
commit
c503a75873
1 changed files with 5 additions and 3 deletions
  1. 5 3
      core/net/dns.odin

+ 5 - 3
core/net/dns.odin

@@ -373,18 +373,20 @@ load_resolv_conf :: proc(resolv_conf_path: string, allocator := context.allocato
 	defer delete(res)
 	defer delete(res)
 	resolv_str := string(res)
 	resolv_str := string(res)
 
 
+	id_str := "nameserver"
+	id_len := len(id_str)
+
 	_name_servers := make([dynamic]Endpoint, 0, allocator)
 	_name_servers := make([dynamic]Endpoint, 0, allocator)
 	for line in strings.split_lines_iterator(&resolv_str) {
 	for line in strings.split_lines_iterator(&resolv_str) {
 		if len(line) == 0 || line[0] == '#' {
 		if len(line) == 0 || line[0] == '#' {
 			continue
 			continue
 		}
 		}
 
 
-		id_str := "nameserver"
-		if strings.compare(line[:len(id_str)], id_str) != 0 {
+		if len(line) < id_len || strings.compare(line[:id_len], id_str) != 0 {
 			continue
 			continue
 		}
 		}
 
 
-		server_ip_str := strings.trim_left_space(line[len(id_str):])
+		server_ip_str := strings.trim_left_space(line[id_len:])
 		if len(server_ip_str) == 0 {
 		if len(server_ip_str) == 0 {
 			continue
 			continue
 		}
 		}