Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-integ / recipes-support / dnsmasq / dnsmasq / stx / dnsmasq-2.76-coverity.patch
1 From 7ab5d6bd1f8b018c73341f50a395405dee6873d8 Mon Sep 17 00:00:00 2001
2 From: rpm-build <rpm-build>
3 Date: Wed, 15 Mar 2017 14:26:04 +0100
4 Subject: [PATCH] Coverity fixes
5
6 ---
7  src/dbus.c        |  2 +-
8  src/dhcp-common.c |  2 +-
9  src/dhcp.c        |  4 ++--
10  src/dnsmasq.h     |  2 +-
11  src/edns0.c       |  2 ++
12  src/inotify.c     |  9 ++++++---
13  src/lease.c       |  4 ++--
14  src/network.c     |  8 ++++----
15  src/option.c      | 16 +++++++++++-----
16  src/tftp.c        |  2 +-
17  src/util.c        |  2 +-
18  11 files changed, 32 insertions(+), 21 deletions(-)
19
20 diff --git a/src/dbus.c b/src/dbus.c
21 index 2e1a48e..f27ec3e 100644
22 --- a/src/dbus.c
23 +++ b/src/dbus.c
24 @@ -550,7 +550,7 @@ static DBusMessage *dbus_add_lease(DBusMessage* message)
25                                          "Invalid IP address '%s'", ipaddr);
26     
27    hw_len = parse_hex((char*)hwaddr, dhcp_chaddr, DHCP_CHADDR_MAX, NULL, &hw_type);
28 -  if (hw_type == 0 && hw_len != 0)
29 +  if (hw_type == 0 && hw_len > 0)
30      hw_type = ARPHRD_ETHER;
31    
32    lease_set_hwaddr(lease, dhcp_chaddr, clid, hw_len, hw_type,
33 diff --git a/src/dhcp-common.c b/src/dhcp-common.c
34 index 08528e8..ebf06b6 100644
35 --- a/src/dhcp-common.c
36 +++ b/src/dhcp-common.c
37 @@ -487,7 +487,7 @@ void  bindtodevice(char *device, int fd)
38  {
39    struct ifreq ifr;
40    
41 -  strcpy(ifr.ifr_name, device);
42 +  strncpy(ifr.ifr_name, device, IF_NAMESIZE-1);
43    /* only allowed by root. */
44    if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) == -1 &&
45        errno != EPERM)
46 diff --git a/src/dhcp.c b/src/dhcp.c
47 index 10f1fb9..37bb71e 100644
48 --- a/src/dhcp.c
49 +++ b/src/dhcp.c
50 @@ -246,7 +246,7 @@ void dhcp_packet(time_t now, int pxe_fd)
51               }
52             else 
53               {
54 -               strncpy(ifr.ifr_name,  bridge->iface, IF_NAMESIZE);
55 +               strncpy(ifr.ifr_name,  bridge->iface, IF_NAMESIZE-1);
56                 break;
57               }
58           }
59 @@ -270,7 +270,7 @@ void dhcp_packet(time_t now, int pxe_fd)
60        is_relay_reply = 1; 
61        iov.iov_len = sz;
62  #ifdef HAVE_LINUX_NETWORK
63 -      strncpy(arp_req.arp_dev, ifr.ifr_name, 16);
64 +      strncpy(arp_req.arp_dev, ifr.ifr_name, IF_NAMESIZE-1);
65  #endif 
66      }
67    else
68 diff --git a/src/dnsmasq.h b/src/dnsmasq.h
69 index dfd15aa..1179492 100644
70 --- a/src/dnsmasq.h
71 +++ b/src/dnsmasq.h
72 @@ -180,7 +180,7 @@ struct event_desc {
73  #define EC_INIT_OFFSET 10
74  
75  /* Trust the compiler dead-code eliminator.... */
76 -#define option_bool(x) (((x) < 32) ? daemon->options & (1u << (x)) : daemon->options2 & (1u << ((x) - 32)))
77 +#define option_bool(x) (((x) < 32) ? daemon->options & (1u << ((x)&0x1F)) : daemon->options2 & (1u << ((x) - 32)))
78  
79  #define OPT_BOGUSPRIV      0
80  #define OPT_FILTER         1
81 diff --git a/src/edns0.c b/src/edns0.c
82 index c7a101e..d2b514b 100644
83 --- a/src/edns0.c
84 +++ b/src/edns0.c
85 @@ -263,6 +263,8 @@ static size_t add_dns_client(struct dns_header *header, size_t plen, unsigned ch
86           encode[8] = 0;
87         }
88      }
89 +  else
90 +    encode[0] = '\0';
91  
92    return add_pseudoheader(header, plen, limit, PACKETSZ, EDNS0_OPTION_NOMDEVICEID, (unsigned char *)encode, strlen(encode), 0, replace); 
93  }
94 diff --git a/src/inotify.c b/src/inotify.c
95 index 603ce9d..fcc0d97 100644
96 --- a/src/inotify.c
97 +++ b/src/inotify.c
98 @@ -224,17 +224,20 @@ int inotify_check(time_t now)
99        
100        if (rc <= 0)
101         break;
102 +      else
103 +        inotify_buffer[rc] = '\0';
104        
105        for (p = inotify_buffer; rc - (p - inotify_buffer) >= (int)sizeof(struct inotify_event); p += sizeof(struct inotify_event) + in->len) 
106         {
107           in = (struct inotify_event*)p;
108 -         
109 +
110           for (res = daemon->resolv_files; res; res = res->next)
111 -           if (res->wd == in->wd && in->len != 0 && strcmp(res->file, in->name) == 0)
112 +           if (res->wd == in->wd && in->len != 0 && strncmp(res->file, in->name, NAME_MAX) == 0)
113               hit = 1;
114  
115           /* ignore emacs backups and dotfiles */
116 -         if (in->len == 0 || 
117 +         if (in->len == 0 ||
118 +             in->len > NAME_MAX+1 ||
119               in->name[in->len - 1] == '~' ||
120               (in->name[0] == '#' && in->name[in->len - 1] == '#') ||
121               in->name[0] == '.')
122 diff --git a/src/lease.c b/src/lease.c
123 index 20cac90..9ad106d 100644
124 --- a/src/lease.c
125 +++ b/src/lease.c
126 @@ -827,9 +827,9 @@ void lease_set_hwaddr(struct dhcp_lease *lease, const unsigned char *hwaddr,
127  
128    if (hw_len != lease->hwaddr_len ||
129        hw_type != lease->hwaddr_type || 
130 -      (hw_len != 0 && memcmp(lease->hwaddr, hwaddr, hw_len) != 0))
131 +      (hw_len > 0 && memcmp(lease->hwaddr, hwaddr, hw_len) != 0))
132      {
133 -      if (hw_len != 0)
134 +      if (hw_len > 0)
135         memcpy(lease->hwaddr, hwaddr, hw_len);
136        lease->hwaddr_len = hw_len;
137        lease->hwaddr_type = hw_type;
138 diff --git a/src/network.c b/src/network.c
139 index 6119039..fcd9d8d 100644
140 --- a/src/network.c
141 +++ b/src/network.c
142 @@ -188,7 +188,7 @@ int loopback_exception(int fd, int family, struct all_addr *addr, char *name)
143    struct ifreq ifr;
144    struct irec *iface;
145  
146 -  strncpy(ifr.ifr_name, name, IF_NAMESIZE);
147 +  strncpy(ifr.ifr_name, name, IF_NAMESIZE-1);
148    if (ioctl(fd, SIOCGIFFLAGS, &ifr) != -1 &&
149        ifr.ifr_flags & IFF_LOOPBACK)
150      {
151 @@ -1206,7 +1206,7 @@ int local_bind(int fd, union mysockaddr *addr, char *intname, int is_tcp)
152      return 0;
153      
154  #if defined(SO_BINDTODEVICE)
155 -  if (intname[0] != 0 &&
156 +  if (intname && intname[0] != 0 &&
157        setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, intname, IF_NAMESIZE) == -1)
158      return 0;
159  #endif
160 @@ -1245,7 +1245,7 @@ static struct serverfd *allocate_sfd(union mysockaddr *addr, char *intname)
161    /* may have a suitable one already */
162    for (sfd = daemon->sfds; sfd; sfd = sfd->next )
163      if (sockaddr_isequal(&sfd->source_addr, addr) &&
164 -       strcmp(intname, sfd->interface) == 0 &&
165 +       intname && strcmp(intname, sfd->interface) == 0 &&
166         ifindex == sfd->ifindex) 
167        return sfd;
168    
169 @@ -1437,7 +1437,7 @@ void add_update_server(int flags,
170         serv->flags |= SERV_HAS_DOMAIN;
171        
172        if (interface)
173 -       strcpy(serv->interface, interface);      
174 +       strncpy(serv->interface, interface, sizeof(serv->interface)-1);
175        if (addr)
176         serv->addr = *addr;
177        if (source_addr)
178 diff --git a/src/option.c b/src/option.c
179 index 5503b79..eb78b1a 100644
180 --- a/src/option.c
181 +++ b/src/option.c
182 @@ -3929,13 +3929,15 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
183        
184      case LOPT_HOST_REC: /* --host-record */
185        {
186 -       struct host_record *new = opt_malloc(sizeof(struct host_record));
187 -       memset(new, 0, sizeof(struct host_record));
188 -       new->ttl = -1;
189 +       struct host_record *new;
190  
191         if (!arg || !(comma = split(arg)))
192           ret_err(_("Bad host-record"));
193         
194 +       new = opt_malloc(sizeof(struct host_record));
195 +       memset(new, 0, sizeof(struct host_record));
196 +       new->ttl = -1;
197 +
198         while (arg)
199           {
200             struct all_addr addr;
201 @@ -3956,10 +3958,11 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
202               {
203                 int nomem;
204                 char *canon = canonicalise(arg, &nomem);
205 -               struct name_list *nl = opt_malloc(sizeof(struct name_list));
206 +               struct name_list *nl;
207                 if (!canon)
208                   ret_err(_("Bad name in host-record"));
209  
210 +               nl = opt_malloc(sizeof(struct name_list));
211                 nl->name = canon;
212                 /* keep order, so that PTR record goes to first name */
213                 nl->next = NULL;
214 @@ -4023,7 +4026,10 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
215             !atoi_check8(algo, &new->algo) ||
216             !atoi_check8(digest, &new->digest_type) ||
217             !(new->name = canonicalise_opt(arg)))
218 -         ret_err(_("bad trust anchor"));
219 +         {
220 +           free(new);
221 +           ret_err(_("bad trust anchor"));
222 +         }
223             
224         /* Upper bound on length */
225         len = (2*strlen(keyhex))+1;
226 diff --git a/src/tftp.c b/src/tftp.c
227 index 5e4a32a..bd8c622 100644
228 --- a/src/tftp.c
229 +++ b/src/tftp.c
230 @@ -234,7 +234,7 @@ void tftp_request(struct listener *listen, time_t now)
231  #endif
232         }
233  
234 -      strncpy(ifr.ifr_name, name, IF_NAMESIZE);
235 +      strncpy(ifr.ifr_name, name, IF_NAMESIZE-1);
236        if (ioctl(listen->tftpfd, SIOCGIFMTU, &ifr) != -1)
237         {
238           mtu = ifr.ifr_mtu;  
239 diff --git a/src/util.c b/src/util.c
240 index 93b24f5..1a9f228 100644
241 --- a/src/util.c
242 +++ b/src/util.c
243 @@ -491,7 +491,7 @@ int parse_hex(char *in, unsigned char *out, int maxlen,
244                   int j, bytes = (1 + (r - in))/2;
245                   for (j = 0; j < bytes; j++)
246                     { 
247 -                     char sav = sav;
248 +                     char sav;
249                       if (j < bytes - 1)
250                         {
251                           sav = in[(j+1)*2];
252 -- 
253 2.9.3
254