summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormillert <>2004-12-20 22:33:09 +0000
committermillert <>2004-12-20 22:33:09 +0000
commit1162f5676951c2e5a415889f56385c0663c2f6fd (patch)
tree595348c97ea7f2879d7ee23c921de4017faf9ea4 /src
parent04593fd1f06297315cafac4b57721e20b09013c7 (diff)
downloadopenbsd-1162f5676951c2e5a415889f56385c0663c2f6fd.tar.gz
openbsd-1162f5676951c2e5a415889f56385c0663c2f6fd.tar.bz2
openbsd-1162f5676951c2e5a415889f56385c0663c2f6fd.zip
Add Itojun's CAVEATS section.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/net/getnameinfo.356
1 files changed, 55 insertions, 1 deletions
diff --git a/src/lib/libc/net/getnameinfo.3 b/src/lib/libc/net/getnameinfo.3
index 9085ff6971..050ec5a442 100644
--- a/src/lib/libc/net/getnameinfo.3
+++ b/src/lib/libc/net/getnameinfo.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: getnameinfo.3,v 1.32 2004/12/20 22:30:10 millert Exp $ 1.\" $OpenBSD: getnameinfo.3,v 1.33 2004/12/20 22:33:09 millert Exp $
2.\" 2.\"
3.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") 3.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
4.\" Copyright (C) 2000, 2001 Internet Software Consortium. 4.\" Copyright (C) 2000, 2001 Internet Software Consortium.
@@ -197,6 +197,60 @@ function is defined by the
197draft specification and documented in 197draft specification and documented in
198.Tn "RFC 2553" , 198.Tn "RFC 2553" ,
199.Dq Basic Socket Interface Extensions for IPv6 . 199.Dq Basic Socket Interface Extensions for IPv6 .
200.Sh CAVEATS
201.Fn getnameinfo
202can return both numeric and FQDN forms of the address specified in
203.Fa sa .
204There is no return value that indicates whether the string returned in
205.Fa host
206is a result of binary to numeric-text translation (like
207.Xr inet_ntop 3 ) ,
208or is the result of a DNS reverse lookup.
209Because of this, malicious parties could set up a PTR record as follows:
210.Bd -literal -offset indent
2111.0.0.127.in-addr.arpa. IN PTR 10.1.1.1
212.Ed
213.Pp
214and trick the caller of
215.Fn getnameinfo
216into believing that
217.Fa sa
218is
219.Li 10.1.1.1
220when it is actually
221.Li 127.0.0.1 .
222.Pp
223To prevent such attacks, the use of
224.Dv NI_NAMEREQD
225is recommended when you use the result of
226.Fn getnameinfo
227for access control purposes:
228.Bd -literal -offset indent
229struct sockaddr *sa;
230socklen_t salen;
231char addr[NI_MAXHOST];
232struct addrinfo hints, *res;
233int error;
234
235error = getnameinfo(sa, salen, addr, sizeof(addr),
236 NULL, 0, NI_NAMEREQD);
237if (error == 0) {
238 memset(&hints, 0, sizeof(hints));
239 hints.ai_socktype = SOCK_DGRAM; /*dummy*/
240 hints.ai_flags = AI_NUMERICHOST;
241 if (getaddrinfo(addr, "0", &hints, &res) == 0) {
242 /* malicious PTR record */
243 freeaddrinfo(res);
244 printf("bogus PTR record\\n");
245 return -1;
246 }
247 /* addr is FQDN as a result of PTR lookup */
248} else {
249 /* addr is numeric string */
250 error = getnameinfo(sa, salen, addr, sizeof(addr),
251 NULL, 0, NI_NUMERICHOST);
252}
253.Ed
200.Sh BUGS 254.Sh BUGS
201Due to the use of dynamic allocation, 255Due to the use of dynamic allocation,
202.Fn getaddrinfo 256.Fn getaddrinfo