oss-fuzz/projects/dnsmasq/fuzz_patch.patch

149 lines
4.0 KiB
Diff
Raw Normal View History

diff --git a/src/blockdata.c b/src/blockdata.c
2022-02-08 22:51:27 +00:00
index 4c26155..9612447 100644
--- a/src/blockdata.c
+++ b/src/blockdata.c
@@ -15,16 +15,22 @@
*/
#include "dnsmasq.h"
+#include <assert.h>
static struct blockdata *keyblock_free;
static unsigned int blockdata_count, blockdata_hwm, blockdata_alloced;
+void *total_allocated[200] = {0};
+static int fuzz_total_alloc_ptr = 0;
+
static void blockdata_expand(int n)
{
struct blockdata *new = whine_malloc(n * sizeof(struct blockdata));
if (new)
{
+ assert(fuzz_total_alloc_ptr < 200);
+ total_allocated[fuzz_total_alloc_ptr++] = (void*)new;
int i;
new[n-1].next = keyblock_free;
@@ -45,11 +51,23 @@ void blockdata_init(void)
blockdata_count = 0;
blockdata_hwm = 0;
+ fuzz_total_alloc_ptr = 0;
+ for (int m = 0; m < 200; m++)
2021-09-20 13:49:13 +00:00
+ total_allocated[m] = NULL;
+
/* Note that daemon->cachesize is enforced to have non-zero size if OPT_DNSSEC_VALID is set */
if (option_bool(OPT_DNSSEC_VALID))
blockdata_expand(daemon->cachesize);
}
+void fuzz_blockdata_cleanup() {
2021-09-20 13:49:13 +00:00
+ for (int i = 0; i < 200; i++) {
+ if (total_allocated[i] != NULL) {
+ free(total_allocated[i]);
+ }
+ }
+}
+
void blockdata_report(void)
{
2021-09-20 13:49:13 +00:00
my_syslog(LOG_INFO, _("pool memory in use %zu, max %zu, allocated %zu"),
diff --git a/src/dhcp.c b/src/dhcp.c
2022-02-08 22:51:27 +00:00
index 6104c87..0a42ac3 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
2022-02-08 22:51:27 +00:00
@@ -186,7 +186,13 @@ void dhcp_packet(time_t now, int pxe_fd)
recvtime = tv.tv_sec;
2022-02-08 22:51:27 +00:00
if (msg.msg_controllen >= sizeof(struct cmsghdr))
- for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
+ {
+ int tmp_val = 0;
2022-02-08 22:51:27 +00:00
+ for (cmptr = CMSG_FIRSTHDR(&msg);
+ cmptr && tmp_val < 1;
+ tmp_val++) {
+ //cmptr = CMSG_NXTHDR(&msg, cmptr)) {
+ tmp_val++;
2022-02-08 22:51:27 +00:00
if (cmptr->cmsg_level == IPPROTO_IP && cmptr->cmsg_type == IP_PKTINFO)
{
union {
@@ -198,6 +204,8 @@ void dhcp_packet(time_t now, int pxe_fd)
if (p.p->ipi_addr.s_addr != INADDR_BROADCAST)
unicast_dest = 1;
}
+ }
+ }
#elif defined(HAVE_BSD_NETWORK)
if (msg.msg_controllen >= sizeof(struct cmsghdr))
diff --git a/src/dhcp6.c b/src/dhcp6.c
2022-02-08 22:51:27 +00:00
index edb87a4..937b5a7 100644
--- a/src/dhcp6.c
+++ b/src/dhcp6.c
2022-02-08 22:51:27 +00:00
@@ -123,7 +123,9 @@ void dhcp6_packet(time_t now)
(union mysockaddr *)&from, NULL, DHCPV6_SERVER_PORT);
#endif
- for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
+ int tmp_val = 0;
+ for (cmptr = CMSG_FIRSTHDR(&msg); cmptr && tmp_val < 1; tmp_val++) {
2022-02-08 22:51:27 +00:00
+ tmp_val++;
if (cmptr->cmsg_level == IPPROTO_IPV6 && cmptr->cmsg_type == daemon->v6pktinfo)
{
union {
2022-02-08 22:51:27 +00:00
@@ -135,9 +137,11 @@ void dhcp6_packet(time_t now)
if_index = p.p->ipi6_ifindex;
dst_addr = p.p->ipi6_addr;
}
+ }
- if (!indextoname(daemon->dhcp6fd, if_index, ifr.ifr_name))
+ if (!indextoname(daemon->dhcp6fd, if_index, ifr.ifr_name)) {
return;
+ }
2022-02-08 22:51:27 +00:00
if (relay_reply6(&from, sz, ifr.ifr_name))
{
diff --git a/src/netlink.c b/src/netlink.c
2022-02-08 22:51:27 +00:00
index da82943..819b3c0 100644
--- a/src/netlink.c
+++ b/src/netlink.c
2022-02-08 22:51:27 +00:00
@@ -190,8 +190,13 @@ int iface_enumerate(int family, void *parm, int (*callback)())
if (errno != 0)
return 0;
+ int valval = 0;
while (1)
{
+ valval++;
+ if (valval > 300) {
+ return -1;
+ }
if ((len = netlink_recv(0)) == -1)
{
if (errno == ENOBUFS)
diff --git a/src/network.c b/src/network.c
2022-02-08 22:51:27 +00:00
index 4453b05..3740cf3 100644
--- a/src/network.c
+++ b/src/network.c
2022-02-08 22:51:27 +00:00
@@ -696,6 +696,7 @@ int enumerate_interfaces(int reset)
struct auth_zone *zone;
#endif
struct server *serv;
+ int iteration = 0;
/* Do this max once per select cycle - also inhibits netlink socket use
in TCP child processes. */
2022-02-08 22:51:27 +00:00
@@ -733,6 +734,10 @@ int enumerate_interfaces(int reset)
}
again:
+ if (iteration > 100) {
+ return 0;
+ }
+ iteration += 1;
/* Mark interfaces for garbage collection */
for (iface = daemon->interfaces; iface; iface = iface->next)
iface->found = 0;