|
|
e20e41 |
From 7ab5d6bd1f8b018c73341f50a395405dee6873d8 Mon Sep 17 00:00:00 2001
|
|
|
e20e41 |
From: rpm-build <rpm-build>
|
|
|
e20e41 |
Date: Wed, 15 Mar 2017 14:26:04 +0100
|
|
|
e20e41 |
Subject: [PATCH] Coverity fixes
|
|
|
e20e41 |
|
|
|
e20e41 |
---
|
|
|
e20e41 |
src/dbus.c | 2 +-
|
|
|
e20e41 |
src/dhcp-common.c | 2 +-
|
|
|
e20e41 |
src/dhcp.c | 4 ++--
|
|
|
e20e41 |
src/dnsmasq.h | 2 +-
|
|
|
e20e41 |
src/edns0.c | 2 ++
|
|
|
e20e41 |
src/inotify.c | 9 ++++++---
|
|
|
e20e41 |
src/lease.c | 4 ++--
|
|
|
e20e41 |
src/network.c | 8 ++++----
|
|
|
e20e41 |
src/option.c | 16 +++++++++++-----
|
|
|
e20e41 |
src/tftp.c | 2 +-
|
|
|
e20e41 |
src/util.c | 2 +-
|
|
|
e20e41 |
11 files changed, 32 insertions(+), 21 deletions(-)
|
|
|
e20e41 |
|
|
|
e20e41 |
diff --git a/src/dbus.c b/src/dbus.c
|
|
|
e20e41 |
index 2e1a48e..f27ec3e 100644
|
|
|
e20e41 |
--- a/src/dbus.c
|
|
|
e20e41 |
+++ b/src/dbus.c
|
|
|
e20e41 |
@@ -550,7 +550,7 @@ static DBusMessage *dbus_add_lease(DBusMessage* message)
|
|
|
e20e41 |
"Invalid IP address '%s'", ipaddr);
|
|
|
e20e41 |
|
|
|
e20e41 |
hw_len = parse_hex((char*)hwaddr, dhcp_chaddr, DHCP_CHADDR_MAX, NULL, &hw_type);
|
|
|
e20e41 |
- if (hw_type == 0 && hw_len != 0)
|
|
|
e20e41 |
+ if (hw_type == 0 && hw_len > 0)
|
|
|
e20e41 |
hw_type = ARPHRD_ETHER;
|
|
|
e20e41 |
|
|
|
e20e41 |
lease_set_hwaddr(lease, dhcp_chaddr, clid, hw_len, hw_type,
|
|
|
e20e41 |
diff --git a/src/dhcp-common.c b/src/dhcp-common.c
|
|
|
e20e41 |
index 08528e8..ebf06b6 100644
|
|
|
e20e41 |
--- a/src/dhcp-common.c
|
|
|
e20e41 |
+++ b/src/dhcp-common.c
|
|
|
e20e41 |
@@ -487,7 +487,7 @@ void bindtodevice(char *device, int fd)
|
|
|
e20e41 |
{
|
|
|
e20e41 |
struct ifreq ifr;
|
|
|
e20e41 |
|
|
|
e20e41 |
- strcpy(ifr.ifr_name, device);
|
|
|
e20e41 |
+ strncpy(ifr.ifr_name, device, IF_NAMESIZE-1);
|
|
|
e20e41 |
/* only allowed by root. */
|
|
|
e20e41 |
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) == -1 &&
|
|
|
e20e41 |
errno != EPERM)
|
|
|
e20e41 |
diff --git a/src/dhcp.c b/src/dhcp.c
|
|
|
e20e41 |
index 10f1fb9..37bb71e 100644
|
|
|
e20e41 |
--- a/src/dhcp.c
|
|
|
e20e41 |
+++ b/src/dhcp.c
|
|
|
e20e41 |
@@ -246,7 +246,7 @@ void dhcp_packet(time_t now, int pxe_fd)
|
|
|
e20e41 |
}
|
|
|
e20e41 |
else
|
|
|
e20e41 |
{
|
|
|
e20e41 |
- strncpy(ifr.ifr_name, bridge->iface, IF_NAMESIZE);
|
|
|
e20e41 |
+ strncpy(ifr.ifr_name, bridge->iface, IF_NAMESIZE-1);
|
|
|
e20e41 |
break;
|
|
|
e20e41 |
}
|
|
|
e20e41 |
}
|
|
|
e20e41 |
@@ -270,7 +270,7 @@ void dhcp_packet(time_t now, int pxe_fd)
|
|
|
e20e41 |
is_relay_reply = 1;
|
|
|
e20e41 |
iov.iov_len = sz;
|
|
|
e20e41 |
#ifdef HAVE_LINUX_NETWORK
|
|
|
e20e41 |
- strncpy(arp_req.arp_dev, ifr.ifr_name, 16);
|
|
|
e20e41 |
+ strncpy(arp_req.arp_dev, ifr.ifr_name, IF_NAMESIZE-1);
|
|
|
e20e41 |
#endif
|
|
|
e20e41 |
}
|
|
|
e20e41 |
else
|
|
|
e20e41 |
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
|
|
|
e20e41 |
index dfd15aa..1179492 100644
|
|
|
e20e41 |
--- a/src/dnsmasq.h
|
|
|
e20e41 |
+++ b/src/dnsmasq.h
|
|
|
e20e41 |
@@ -180,7 +180,7 @@ struct event_desc {
|
|
|
e20e41 |
#define EC_INIT_OFFSET 10
|
|
|
e20e41 |
|
|
|
e20e41 |
/* Trust the compiler dead-code eliminator.... */
|
|
|
e20e41 |
-#define option_bool(x) (((x) < 32) ? daemon->options & (1u << (x)) : daemon->options2 & (1u << ((x) - 32)))
|
|
|
e20e41 |
+#define option_bool(x) (((x) < 32) ? daemon->options & (1u << ((x)&0x1F)) : daemon->options2 & (1u << ((x) - 32)))
|
|
|
e20e41 |
|
|
|
e20e41 |
#define OPT_BOGUSPRIV 0
|
|
|
e20e41 |
#define OPT_FILTER 1
|
|
|
e20e41 |
diff --git a/src/edns0.c b/src/edns0.c
|
|
|
e20e41 |
index c7a101e..d2b514b 100644
|
|
|
e20e41 |
--- a/src/edns0.c
|
|
|
e20e41 |
+++ b/src/edns0.c
|
|
|
e20e41 |
@@ -263,6 +263,8 @@ static size_t add_dns_client(struct dns_header *header, size_t plen, unsigned ch
|
|
|
e20e41 |
encode[8] = 0;
|
|
|
e20e41 |
}
|
|
|
e20e41 |
}
|
|
|
e20e41 |
+ else
|
|
|
e20e41 |
+ encode[0] = '\0';
|
|
|
e20e41 |
|
|
|
e20e41 |
return add_pseudoheader(header, plen, limit, PACKETSZ, EDNS0_OPTION_NOMDEVICEID, (unsigned char *)encode, strlen(encode), 0, replace);
|
|
|
e20e41 |
}
|
|
|
e20e41 |
diff --git a/src/inotify.c b/src/inotify.c
|
|
|
e20e41 |
index 603ce9d..fcc0d97 100644
|
|
|
e20e41 |
--- a/src/inotify.c
|
|
|
e20e41 |
+++ b/src/inotify.c
|
|
|
e20e41 |
@@ -224,17 +224,20 @@ int inotify_check(time_t now)
|
|
|
e20e41 |
|
|
|
e20e41 |
if (rc <= 0)
|
|
|
e20e41 |
break;
|
|
|
e20e41 |
+ else
|
|
|
e20e41 |
+ inotify_buffer[rc] = '\0';
|
|
|
e20e41 |
|
|
|
e20e41 |
for (p = inotify_buffer; rc - (p - inotify_buffer) >= (int)sizeof(struct inotify_event); p += sizeof(struct inotify_event) + in->len)
|
|
|
e20e41 |
{
|
|
|
e20e41 |
in = (struct inotify_event*)p;
|
|
|
e20e41 |
-
|
|
|
e20e41 |
+
|
|
|
e20e41 |
for (res = daemon->resolv_files; res; res = res->next)
|
|
|
e20e41 |
- if (res->wd == in->wd && in->len != 0 && strcmp(res->file, in->name) == 0)
|
|
|
e20e41 |
+ if (res->wd == in->wd && in->len != 0 && strncmp(res->file, in->name, NAME_MAX) == 0)
|
|
|
e20e41 |
hit = 1;
|
|
|
e20e41 |
|
|
|
e20e41 |
/* ignore emacs backups and dotfiles */
|
|
|
e20e41 |
- if (in->len == 0 ||
|
|
|
e20e41 |
+ if (in->len == 0 ||
|
|
|
e20e41 |
+ in->len > NAME_MAX+1 ||
|
|
|
e20e41 |
in->name[in->len - 1] == '~' ||
|
|
|
e20e41 |
(in->name[0] == '#' && in->name[in->len - 1] == '#') ||
|
|
|
e20e41 |
in->name[0] == '.')
|
|
|
e20e41 |
diff --git a/src/lease.c b/src/lease.c
|
|
|
e20e41 |
index 20cac90..9ad106d 100644
|
|
|
e20e41 |
--- a/src/lease.c
|
|
|
e20e41 |
+++ b/src/lease.c
|
|
|
e20e41 |
@@ -827,9 +827,9 @@ void lease_set_hwaddr(struct dhcp_lease *lease, const unsigned char *hwaddr,
|
|
|
e20e41 |
|
|
|
e20e41 |
if (hw_len != lease->hwaddr_len ||
|
|
|
e20e41 |
hw_type != lease->hwaddr_type ||
|
|
|
e20e41 |
- (hw_len != 0 && memcmp(lease->hwaddr, hwaddr, hw_len) != 0))
|
|
|
e20e41 |
+ (hw_len > 0 && memcmp(lease->hwaddr, hwaddr, hw_len) != 0))
|
|
|
e20e41 |
{
|
|
|
e20e41 |
- if (hw_len != 0)
|
|
|
e20e41 |
+ if (hw_len > 0)
|
|
|
e20e41 |
memcpy(lease->hwaddr, hwaddr, hw_len);
|
|
|
e20e41 |
lease->hwaddr_len = hw_len;
|
|
|
e20e41 |
lease->hwaddr_type = hw_type;
|
|
|
e20e41 |
diff --git a/src/network.c b/src/network.c
|
|
|
e20e41 |
index 6119039..fcd9d8d 100644
|
|
|
e20e41 |
--- a/src/network.c
|
|
|
e20e41 |
+++ b/src/network.c
|
|
|
e20e41 |
@@ -188,7 +188,7 @@ int loopback_exception(int fd, int family, struct all_addr *addr, char *name)
|
|
|
e20e41 |
struct ifreq ifr;
|
|
|
e20e41 |
struct irec *iface;
|
|
|
e20e41 |
|
|
|
e20e41 |
- strncpy(ifr.ifr_name, name, IF_NAMESIZE);
|
|
|
e20e41 |
+ strncpy(ifr.ifr_name, name, IF_NAMESIZE-1);
|
|
|
e20e41 |
if (ioctl(fd, SIOCGIFFLAGS, &ifr) != -1 &&
|
|
|
e20e41 |
ifr.ifr_flags & IFF_LOOPBACK)
|
|
|
e20e41 |
{
|
|
|
e20e41 |
@@ -1206,7 +1206,7 @@ int local_bind(int fd, union mysockaddr *addr, char *intname, int is_tcp)
|
|
|
e20e41 |
return 0;
|
|
|
e20e41 |
|
|
|
e20e41 |
#if defined(SO_BINDTODEVICE)
|
|
|
e20e41 |
- if (intname[0] != 0 &&
|
|
|
e20e41 |
+ if (intname && intname[0] != 0 &&
|
|
|
e20e41 |
setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, intname, IF_NAMESIZE) == -1)
|
|
|
e20e41 |
return 0;
|
|
|
e20e41 |
#endif
|
|
|
e20e41 |
@@ -1245,7 +1245,7 @@ static struct serverfd *allocate_sfd(union mysockaddr *addr, char *intname)
|
|
|
e20e41 |
/* may have a suitable one already */
|
|
|
e20e41 |
for (sfd = daemon->sfds; sfd; sfd = sfd->next )
|
|
|
e20e41 |
if (sockaddr_isequal(&sfd->source_addr, addr) &&
|
|
|
e20e41 |
- strcmp(intname, sfd->interface) == 0 &&
|
|
|
e20e41 |
+ intname && strcmp(intname, sfd->interface) == 0 &&
|
|
|
e20e41 |
ifindex == sfd->ifindex)
|
|
|
e20e41 |
return sfd;
|
|
|
e20e41 |
|
|
|
e20e41 |
@@ -1437,7 +1437,7 @@ void add_update_server(int flags,
|
|
|
e20e41 |
serv->flags |= SERV_HAS_DOMAIN;
|
|
|
e20e41 |
|
|
|
e20e41 |
if (interface)
|
|
|
e20e41 |
- strcpy(serv->interface, interface);
|
|
|
e20e41 |
+ strncpy(serv->interface, interface, sizeof(serv->interface)-1);
|
|
|
e20e41 |
if (addr)
|
|
|
e20e41 |
serv->addr = *addr;
|
|
|
e20e41 |
if (source_addr)
|
|
|
e20e41 |
diff --git a/src/option.c b/src/option.c
|
|
|
e20e41 |
index 5503b79..eb78b1a 100644
|
|
|
e20e41 |
--- a/src/option.c
|
|
|
e20e41 |
+++ b/src/option.c
|
|
|
e20e41 |
@@ -3929,13 +3929,15 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
|
|
|
e20e41 |
|
|
|
e20e41 |
case LOPT_HOST_REC: /* --host-record */
|
|
|
e20e41 |
{
|
|
|
e20e41 |
- struct host_record *new = opt_malloc(sizeof(struct host_record));
|
|
|
e20e41 |
- memset(new, 0, sizeof(struct host_record));
|
|
|
e20e41 |
- new->ttl = -1;
|
|
|
e20e41 |
+ struct host_record *new;
|
|
|
e20e41 |
|
|
|
e20e41 |
if (!arg || !(comma = split(arg)))
|
|
|
e20e41 |
ret_err(_("Bad host-record"));
|
|
|
e20e41 |
|
|
|
e20e41 |
+ new = opt_malloc(sizeof(struct host_record));
|
|
|
e20e41 |
+ memset(new, 0, sizeof(struct host_record));
|
|
|
e20e41 |
+ new->ttl = -1;
|
|
|
e20e41 |
+
|
|
|
e20e41 |
while (arg)
|
|
|
e20e41 |
{
|
|
|
e20e41 |
struct all_addr addr;
|
|
|
e20e41 |
@@ -3956,10 +3958,11 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
|
|
|
e20e41 |
{
|
|
|
e20e41 |
int nomem;
|
|
|
e20e41 |
char *canon = canonicalise(arg, &nomem);
|
|
|
e20e41 |
- struct name_list *nl = opt_malloc(sizeof(struct name_list));
|
|
|
e20e41 |
+ struct name_list *nl;
|
|
|
e20e41 |
if (!canon)
|
|
|
e20e41 |
ret_err(_("Bad name in host-record"));
|
|
|
e20e41 |
|
|
|
e20e41 |
+ nl = opt_malloc(sizeof(struct name_list));
|
|
|
e20e41 |
nl->name = canon;
|
|
|
e20e41 |
/* keep order, so that PTR record goes to first name */
|
|
|
e20e41 |
nl->next = NULL;
|
|
|
e20e41 |
@@ -4023,7 +4026,10 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
|
|
|
e20e41 |
!atoi_check8(algo, &new->algo) ||
|
|
|
e20e41 |
!atoi_check8(digest, &new->digest_type) ||
|
|
|
e20e41 |
!(new->name = canonicalise_opt(arg)))
|
|
|
e20e41 |
- ret_err(_("bad trust anchor"));
|
|
|
e20e41 |
+ {
|
|
|
e20e41 |
+ free(new);
|
|
|
e20e41 |
+ ret_err(_("bad trust anchor"));
|
|
|
e20e41 |
+ }
|
|
|
e20e41 |
|
|
|
e20e41 |
/* Upper bound on length */
|
|
|
e20e41 |
len = (2*strlen(keyhex))+1;
|
|
|
e20e41 |
diff --git a/src/tftp.c b/src/tftp.c
|
|
|
e20e41 |
index 5e4a32a..bd8c622 100644
|
|
|
e20e41 |
--- a/src/tftp.c
|
|
|
e20e41 |
+++ b/src/tftp.c
|
|
|
e20e41 |
@@ -234,7 +234,7 @@ void tftp_request(struct listener *listen, time_t now)
|
|
|
e20e41 |
#endif
|
|
|
e20e41 |
}
|
|
|
e20e41 |
|
|
|
e20e41 |
- strncpy(ifr.ifr_name, name, IF_NAMESIZE);
|
|
|
e20e41 |
+ strncpy(ifr.ifr_name, name, IF_NAMESIZE-1);
|
|
|
e20e41 |
if (ioctl(listen->tftpfd, SIOCGIFMTU, &ifr) != -1)
|
|
|
e20e41 |
{
|
|
|
e20e41 |
mtu = ifr.ifr_mtu;
|
|
|
e20e41 |
diff --git a/src/util.c b/src/util.c
|
|
|
e20e41 |
index 93b24f5..1a9f228 100644
|
|
|
e20e41 |
--- a/src/util.c
|
|
|
e20e41 |
+++ b/src/util.c
|
|
|
e20e41 |
@@ -491,7 +491,7 @@ int parse_hex(char *in, unsigned char *out, int maxlen,
|
|
|
e20e41 |
int j, bytes = (1 + (r - in))/2;
|
|
|
e20e41 |
for (j = 0; j < bytes; j++)
|
|
|
e20e41 |
{
|
|
|
e20e41 |
- char sav = sav;
|
|
|
e20e41 |
+ char sav;
|
|
|
e20e41 |
if (j < bytes - 1)
|
|
|
e20e41 |
{
|
|
|
e20e41 |
sav = in[(j+1)*2];
|
|
|
e20e41 |
--
|
|
|
e20e41 |
2.9.3
|
|
|
e20e41 |
|