summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoritojun <>2003-08-28 01:42:18 +0000
committeritojun <>2003-08-28 01:42:18 +0000
commit3dfb08139be6f1d64fe6b2d9cacb6ab24548e6f4 (patch)
treeca57bbc5fdb60a054929f4fc1aa5c3d3c3afe6eb /src
parent688fda2523fc07ae4fcd205943daca3748593805 (diff)
downloadopenbsd-3dfb08139be6f1d64fe6b2d9cacb6ab24548e6f4.tar.gz
openbsd-3dfb08139be6f1d64fe6b2d9cacb6ab24548e6f4.tar.bz2
openbsd-3dfb08139be6f1d64fe6b2d9cacb6ab24548e6f4.zip
add 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 03b6149e01..00c70bdb7a 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.22 2003/08/08 09:26:02 jmc Exp $ 1.\" $OpenBSD: getnameinfo.3,v 1.23 2003/08/28 01:42:18 itojun Exp $
2.\" $KAME: getnameinfo.3,v 1.20 2001/01/05 13:37:37 itojun Exp $ 2.\" $KAME: getnameinfo.3,v 1.20 2001/01/05 13:37:37 itojun Exp $
3.\" 3.\"
4.\" Copyright (c) 1983, 1987, 1991, 1993 4.\" Copyright (c) 1983, 1987, 1991, 1993
@@ -282,6 +282,60 @@ and documented in
282.Sh HISTORY 282.Sh HISTORY
283The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit. 283The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit.
284.\" 284.\"
285.Sh CAVEATS
286.Nm
287returns both numeric and FQDN notation of the address specified in
288.Fa sa .
289There is no return value that indicates if the string returned in
290.Fa host
291is a result of binary to numeric-text translation (like
292.Xr inet_ntop 3
293), or the result of DNS reverse lookup.
294Therefore, malicious parties could set up PTR record like below:
295.Bd -literal -offset indent
2961.0.0.127.in-addr.arpa. IN PTR 10.1.1.1
297.Ed
298.Pp
299and trick the caller of
300.Nm
301to believe that
302.Fa sa
303is
304.Li 10.1.1.1
305when it actually is
306.Li 127.0.0.1 .
307.Pp
308To prevent such attacks, the use of
309.Li NI_NAMEREQD
310like below is recommended when you use the result of
311.Nm
312for access control purposes.
313.Bd -literal -offset indent
314struct sockaddr *sa;
315socklen_t salen;
316char addr[NI_MAXHOST];
317struct addrinfo hints, *res;
318
319error = getnameinfo(sa, salen, addr, sizeof(addr),
320 NULL, 0, NI_NAMEREQD);
321if (error == 0) {
322 memset(&hints, 0, sizeof(hints));
323 hints.ai_socktype = SOCK_DGRAM; /*dummy*/
324 hints.ai_flags = AI_NUMERICHOST;
325 if (getaddrinfo(addr, "0", &hints, &res) == 0) {
326 /* malicious PTR record */
327 freeaddrinfo(res);
328 printf("bogus PTR record\\n");
329 return -1;
330 }
331 /* addr is FQDN as a result of PTR lookup */
332} else {
333 /* addr is numeric string */
334 error = getnameinfo(sa, salen, addr, sizeof(addr),
335 NULL, 0, 0);
336}
337.Ed
338.\"
285.Sh BUGS 339.Sh BUGS
286The current implementation is not thread-safe. 340The current implementation is not thread-safe.
287.Pp 341.Pp