dnsmasq: Backport some security updates
[librecmc/librecmc.git] / package / network / services / dnsmasq / patches / 0107-Add-missing-check-for-NULL-return-from-allocate_rfd.patch
1 From 824461192ca5098043f9ca4ddeba7df1f65b30ba Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Sun, 15 Nov 2020 22:13:25 +0000
4 Subject: Add missing check for NULL return from allocate_rfd().
5
6 ---
7  src/forward.c | 18 ++++++++++--------
8  1 file changed, 10 insertions(+), 8 deletions(-)
9
10 --- a/src/forward.c
11 +++ b/src/forward.c
12 @@ -815,7 +815,6 @@ void reply_query(int fd, int family, tim
13        int is_sign;
14  
15  #ifdef HAVE_DNSSEC
16 -      /* For DNSSEC originated queries, just retry the query to the same server. */
17        if (forward->flags & (FREC_DNSKEY_QUERY | FREC_DS_QUERY))
18         {
19           struct server *start;
20 @@ -841,6 +840,8 @@ void reply_query(int fd, int family, tim
21               }
22             
23           
24 +         fd = -1;
25 +
26           if (start->sfd)
27             fd = start->sfd->fd;
28           else
29 @@ -848,19 +849,21 @@ void reply_query(int fd, int family, tim
30               if (start->addr.sa.sa_family == AF_INET6)
31                 {
32                   /* may have changed family */
33 -                 if (!forward->rfd6)
34 -                   forward->rfd6 = allocate_rfd(AF_INET6);
35 -                 fd = forward->rfd6->fd;
36 +                 if (forward->rfd6 || (forward->rfd6 = allocate_rfd(AF_INET6)))
37 +                   fd = forward->rfd6->fd;
38                 }
39               else
40                 {
41                   /* may have changed family */
42 -                 if (!forward->rfd4)
43 -                   forward->rfd4 = allocate_rfd(AF_INET);
44 -                 fd = forward->rfd4->fd;
45 +                 if (forward->rfd4 || (forward->rfd4 = allocate_rfd(AF_INET)))
46 +                   fd = forward->rfd4->fd;
47                 }
48             }
49         
50 +         /* Can't get socket. */
51 +         if (fd == -1)
52 +           return;
53 +         
54           while (retry_send(sendto(fd, (char *)header, plen, 0,
55                                    &start->addr.sa,
56                                    sa_len(&start->addr))));
57 @@ -2261,7 +2264,6 @@ struct frec *get_new_frec(time_t now, in
58    return f; /* OK if malloc fails and this is NULL */
59  }
60  
61 -/* crc is all-ones if not known. */
62  static struct frec *lookup_frec(unsigned short id, int fd, int family, void *hash)
63  {
64    struct frec *f;