Mon May 13 17:54:55 2013 UTC ()
CVE 1020946: Fix res leak.


(christos)
diff -r1.104 -r1.105 src/lib/libc/net/getaddrinfo.c

cvs diff -r1.104 -r1.105 src/lib/libc/net/getaddrinfo.c (expand / switch to unified diff)

--- src/lib/libc/net/getaddrinfo.c 2013/05/13 13:59:39 1.104
+++ src/lib/libc/net/getaddrinfo.c 2013/05/13 17:54:55 1.105
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: getaddrinfo.c,v 1.104 2013/05/13 13:59:39 christos Exp $ */ 1/* $NetBSD: getaddrinfo.c,v 1.105 2013/05/13 17:54:55 christos Exp $ */
2/* $KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $ */ 2/* $KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -45,27 +45,27 @@ @@ -45,27 +45,27 @@
45 * Note: 45 * Note:
46 * - The code filters out AFs that are not supported by the kernel, 46 * - The code filters out AFs that are not supported by the kernel,
47 * when globbing NULL hostname (to loopback, or wildcard). Is it the right 47 * when globbing NULL hostname (to loopback, or wildcard). Is it the right
48 * thing to do? What is the relationship with post-RFC2553 AI_ADDRCONFIG 48 * thing to do? What is the relationship with post-RFC2553 AI_ADDRCONFIG
49 * in ai_flags? 49 * in ai_flags?
50 * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague. 50 * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague.
51 * (1) what should we do against numeric hostname (2) what should we do 51 * (1) what should we do against numeric hostname (2) what should we do
52 * against NULL hostname (3) what is AI_ADDRCONFIG itself. AF not ready? 52 * against NULL hostname (3) what is AI_ADDRCONFIG itself. AF not ready?
53 * non-loopback address configured? global address configured? 53 * non-loopback address configured? global address configured?
54 */ 54 */
55 55
56#include <sys/cdefs.h> 56#include <sys/cdefs.h>
57#if defined(LIBC_SCCS) && !defined(lint) 57#if defined(LIBC_SCCS) && !defined(lint)
58__RCSID("$NetBSD: getaddrinfo.c,v 1.104 2013/05/13 13:59:39 christos Exp $"); 58__RCSID("$NetBSD: getaddrinfo.c,v 1.105 2013/05/13 17:54:55 christos Exp $");
59#endif /* LIBC_SCCS and not lint */ 59#endif /* LIBC_SCCS and not lint */
60 60
61#include "namespace.h" 61#include "namespace.h"
62#include <sys/types.h> 62#include <sys/types.h>
63#include <sys/param.h> 63#include <sys/param.h>
64#include <sys/socket.h> 64#include <sys/socket.h>
65#include <net/if.h> 65#include <net/if.h>
66#include <netinet/in.h> 66#include <netinet/in.h>
67#include <arpa/inet.h> 67#include <arpa/inet.h>
68#include <arpa/nameser.h> 68#include <arpa/nameser.h>
69#include <assert.h> 69#include <assert.h>
70#include <ctype.h> 70#include <ctype.h>
71#include <errno.h> 71#include <errno.h>
@@ -1659,26 +1659,27 @@ _dns_host_lookup(const char *name, const @@ -1659,26 +1659,27 @@ _dns_host_lookup(const char *name, const
1659 q2.qtype = T_A; 1659 q2.qtype = T_A;
1660 break; 1660 break;
1661 case AF_INET: 1661 case AF_INET:
1662 q.name = name; 1662 q.name = name;
1663 q.qclass = C_IN; 1663 q.qclass = C_IN;
1664 q.qtype = T_A; 1664 q.qtype = T_A;
1665 break; 1665 break;
1666 case AF_INET6: 1666 case AF_INET6:
1667 q.name = name; 1667 q.name = name;
1668 q.qclass = C_IN; 1668 q.qclass = C_IN;
1669 q.qtype = T_AAAA; 1669 q.qtype = T_AAAA;
1670 break; 1670 break;
1671 default: 1671 default:
 1672 __res_put_state(res);
1672 h_errno = NETDB_INTERNAL; 1673 h_errno = NETDB_INTERNAL;
1673 return NULL; 1674 return NULL;
1674 } 1675 }
1675 1676
1676 ai = _dns_query(&q, pai, res, 1); 1677 ai = _dns_query(&q, pai, res, 1);
1677 1678
1678 memset(&sentinel, 0, sizeof(sentinel)); 1679 memset(&sentinel, 0, sizeof(sentinel));
1679 sentinel.ai_next = ai; 1680 sentinel.ai_next = ai;
1680 1681
1681 if (ai != NULL && res->nsort) 1682 if (ai != NULL && res->nsort)
1682 aisort(&sentinel, res); 1683 aisort(&sentinel, res);
1683 1684
1684 __res_put_state(res); 1685 __res_put_state(res);