595be191d457ee6a5cac80807a58f7a44c0e85d5
[librecmc/librecmc-fossil.git] /
1 From 290f19972e9f7b74f818ae211cb535e32f1f314f Mon Sep 17 00:00:00 2001
2 From: Leonid Evdokimov <leon@darkk.net.ru>
3 Date: Tue, 10 Apr 2012 00:57:26 +0400
4 Subject: [PATCH 01/12] Fix bug in DNS resolution - results were ignored (since
5  8179a1ff).
6
7 ---
8  parser.c | 10 +++++-----
9  1 file changed, 5 insertions(+), 5 deletions(-)
10
11 diff --git a/parser.c b/parser.c
12 index 85d3533..6198828 100644
13 --- a/parser.c
14 +++ b/parser.c
15 @@ -295,22 +295,22 @@ static int vp_in_addr(parser_context *context, void *addr, const char *token)
16                 memcpy(addr, &ia, sizeof(ia));
17         }
18         else {
19 -               struct addrinfo *addr, hints;
20 +               struct addrinfo *ainfo, hints;
21                 int err;
22                 memset(&hints, 0, sizeof(hints));
23                 hints.ai_family = AF_INET; /* IPv4-only */
24                 hints.ai_socktype = SOCK_STREAM; /* I want to have one address once and ONLY once, that's why I specify socktype and protocol */
25                 hints.ai_protocol = IPPROTO_TCP;
26                 hints.ai_flags = AI_ADDRCONFIG; /* I don't need IPv4 addrs without IPv4 connectivity */
27 -               err = getaddrinfo(token, NULL, &hints, &addr);
28 +               err = getaddrinfo(token, NULL, &hints, &ainfo);
29                 if (err == 0) {
30                         int count, taken;
31                         struct addrinfo *iter;
32                         struct sockaddr_in *resolved_addr;
33 -                       for (iter = addr, count = 0; iter; iter = iter->ai_next, ++count)
34 +                       for (iter = ainfo, count = 0; iter; iter = iter->ai_next, ++count)
35                                 ;
36                         taken = rand() % count;
37 -                       for (iter = addr; taken > 0; iter = iter->ai_next, --taken)
38 +                       for (iter = ainfo; taken > 0; iter = iter->ai_next, --taken)
39                                 ;
40                         resolved_addr = (struct sockaddr_in*)iter->ai_addr;
41                         assert(resolved_addr->sin_family == iter->ai_family && iter->ai_family == AF_INET);
42 @@ -318,7 +318,7 @@ static int vp_in_addr(parser_context *context, void *addr, const char *token)
43                                 log_error(LOG_WARNING, "%s resolves to %d addresses, using %s",
44                                           token, count, inet_ntoa(resolved_addr->sin_addr));
45                         memcpy(addr, &resolved_addr->sin_addr, sizeof(ia));
46 -                       freeaddrinfo(addr);
47 +                       freeaddrinfo(ainfo);
48                 }
49                 else {
50                         if (err == EAI_SYSTEM)
51 -- 
52 1.9.1
53