dnsmasq: Handle memory allocation failure in make_non_terminals()
[oweals/openwrt.git] / package / network / services / dnsmasq / patches / 0001-Handle-memory-allocation-failure-in-make_non_termina.patch
1 From ea6cc338042094f8023d224e53c244da158e6499 Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Tue, 18 Sep 2018 23:21:17 +0100
4 Subject: [PATCH] Handle memory allocation failure in make_non_terminals()
5
6 Thanks to Kristian Evensen for spotting the problem.
7
8 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
9 ---
10  src/cache.c | 17 ++++++++++-------
11  1 file changed, 10 insertions(+), 7 deletions(-)
12
13 --- a/src/cache.c
14 +++ b/src/cache.c
15 @@ -1360,7 +1360,7 @@ void cache_add_dhcp_entry(char *host_nam
16  static void make_non_terminals(struct crec *source)
17  {
18    char *name = cache_get_name(source);
19 -  struct crec* crecp, *tmp, **up;
20 +  struct crec *crecp, *tmp, **up;
21    int type = F_HOSTS | F_CONFIG;
22  #ifdef HAVE_DHCP
23    if (source->flags & F_DHCP)
24 @@ -1434,12 +1434,15 @@ static void make_non_terminals(struct cr
25  #endif
26         crecp = whine_malloc(sizeof(struct crec));
27  
28 -      *crecp = *source;
29 -      crecp->flags &= ~(F_IPV4 | F_IPV6 | F_CNAME | F_DNSKEY | F_DS | F_REVERSE);
30 -      crecp->flags |= F_NAMEP;
31 -      crecp->name.namep = name;
32 -
33 -      cache_hash(crecp);
34 +      if (crecp)
35 +       {
36 +         *crecp = *source;
37 +         crecp->flags &= ~(F_IPV4 | F_IPV6 | F_CNAME | F_DNSKEY | F_DS | F_REVERSE);
38 +         crecp->flags |= F_NAMEP;
39 +         crecp->name.namep = name;
40 +         
41 +         cache_hash(crecp);
42 +       }
43      }
44  }
45