summaryrefslogtreecommitdiff
path: root/dns.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2008-06-13 04:46:45 +1000
committerDarren Tucker <dtucker@zip.com.au>2008-06-13 04:46:45 +1000
commit30ac73bcc2b2fa7b997cb572e5b03ea9107b7641 (patch)
treed9dde452e7cfedc6d201e976ae98ad1816d7f10b /dns.c
parentd32b28a307b308e5b5b052b4eb2a2c8f396c380b (diff)
- dtucker@cvs.openbsd.org 2008/06/12 00:03:49
[dns.c canohost.c sshconnect.c] Do not pass "0" strings as ports to getaddrinfo because the lookups can slow things down and we never use the service info anyway. bz #859, patch from YOSHIFUJI Hideaki and John Devitofranceschi. ok deraadt@ djm@ djm belives that the reason for the "0" strings is to ensure that it's not possible to call getaddrinfo with both host and port being NULL. In the case of canohost.c host is a local array. In the case of sshconnect.c, it's checked for null immediately before use. In dns.c it ultimately comes from ssh.c:main() and is guaranteed to be non-null but it's not obvious, so I added a warning message in case it is ever passed a null.
Diffstat (limited to 'dns.c')
-rw-r--r--dns.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/dns.c b/dns.c
index a89176f88..a7da03fa3 100644
--- a/dns.c
+++ b/dns.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dns.c,v 1.24 2007/01/03 03:01:40 stevesk Exp $ */ 1/* $OpenBSD: dns.c,v 1.25 2008/06/12 00:03:49 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2003 Wesley Griffin. All rights reserved. 4 * Copyright (c) 2003 Wesley Griffin. All rights reserved.
@@ -145,11 +145,20 @@ is_numeric_hostname(const char *hostname)
145{ 145{
146 struct addrinfo hints, *ai; 146 struct addrinfo hints, *ai;
147 147
148 /*
149 * We shouldn't ever get a null host but if we do then log an error
150 * and return -1 which stops DNS key fingerprint processing.
151 */
152 if (hostname == NULL) {
153 error("is_numeric_hostname called with NULL hostname");
154 return -1;
155 }
156
148 memset(&hints, 0, sizeof(hints)); 157 memset(&hints, 0, sizeof(hints));
149 hints.ai_socktype = SOCK_DGRAM; 158 hints.ai_socktype = SOCK_DGRAM;
150 hints.ai_flags = AI_NUMERICHOST; 159 hints.ai_flags = AI_NUMERICHOST;
151 160
152 if (getaddrinfo(hostname, "0", &hints, &ai) == 0) { 161 if (getaddrinfo(hostname, NULL, &hints, &ai) == 0) {
153 freeaddrinfo(ai); 162 freeaddrinfo(ai);
154 return -1; 163 return -1;
155 } 164 }