Hey Simon,

I have two small patches for dnsmasq to address two oddities I've
seen this week.

Patch 1 fixes an ambiguity with interface names when virtual
interfaces are present.
I'm not exactly sure it has no unintended side-effects, however,
it seems to be the right thing to do in my understanding of the
code. Otherwise, virtual interfaces cannot really be
distinguished from real interfaces later in the code. This may be
a problem when there is more than one virtual interface as iface-
>label will be non-zero for all of them. For instance,
warn_wild_labels() will log the same string multiple times if
more than one virtual interface is present.

Patch 2 fixes a crash I've seen on a small embedded device that
crashed when there wasn't enough memory available for allocating
a TCP packet (66 kilobytes).

Best regards,
Dominik
From e2112e432917caf510b256d5108925270c6da391 Mon Sep 17 00:00:00 2001
From: Dominik DL6ER <dl...@dl6er.de>
Date: Sat, 18 Sep 2021 16:05:34 +0200
Subject: [PATCH 2/2] Check if allocation of 66573 bytes succeeded before
 accessing the memory to avoid crash in busy times

Signed-off-by: DL6ER <dl...@dl6er.de>
---
 src/forward.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/forward.c b/src/forward.c
index f3c38d7..13ce827 100644
--- a/src/forward.c
+++ b/src/forward.c
@@ -1847,6 +1847,8 @@ unsigned char *tcp_request(int confd, time_t now,
   unsigned int gotname;
   /* Max TCP packet + slop + size */
   unsigned char *packet = whine_malloc(65536 + MAXDNAME + RRFIXEDSZ + sizeof(u16));
+  if(!packet)
+    return packet;
   unsigned char *payload = &packet[2];
   unsigned char c1, c2;
   /* largest field in header is 16-bits, so this is still sufficiently aligned */
-- 
2.25.1

From f4e29ed476c31ac977552b5dbf18ce2fa04d0fbc Mon Sep 17 00:00:00 2001
From: Dominik DL6ER <dl...@dl6er.de>
Date: Sat, 18 Sep 2021 15:58:28 +0200
Subject: [PATCH 1/2] Use label instead of interface name to avoid ambiguities
 when virtual interfaces are present. E.g., when having an interface, name
 will both times be "eth0" whereas label will once be "eth0" and once "eth0:0"

Signed-off-by: DL6ER <dl...@dl6er.de>
---
 src/network.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/network.c b/src/network.c
index 3fc179d..d270011 100644
--- a/src/network.c
+++ b/src/network.c
@@ -506,7 +506,7 @@ static int iface_allowed(struct iface_param *param, int if_index, char *label,
     }
   else
     for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
-      if (tmp->name && wildcard_match(tmp->name, ifr.ifr_name))
+      if (tmp->name && wildcard_match(tmp->name, label))
 	{
 	  tftp_ok = 0;
 	  dhcp_ok = 0;
@@ -520,7 +520,7 @@ static int iface_allowed(struct iface_param *param, int if_index, char *label,
       /* dedicated tftp interface list */
       tftp_ok = 0;
       for (tmp = daemon->tftp_interfaces; tmp; tmp = tmp->next)
-	if (tmp->name && wildcard_match(tmp->name, ifr.ifr_name))
+	if (tmp->name && wildcard_match(tmp->name, label))
 	  tftp_ok = 1;
     }
 #endif
@@ -544,9 +544,9 @@ static int iface_allowed(struct iface_param *param, int if_index, char *label,
       iface->done = iface->multicast_done = iface->warned = 0;
       iface->index = if_index;
       iface->label = is_label;
-      if ((iface->name = whine_malloc(strlen(ifr.ifr_name)+1)))
+      if ((iface->name = whine_malloc(strlen(label)+1)))
 	{
-	  strcpy(iface->name, ifr.ifr_name);
+	  strcpy(iface->name, label);
 	  iface->next = daemon->interfaces;
 	  daemon->interfaces = iface;
 	  return 1;
-- 
2.25.1

_______________________________________________
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss

Reply via email to