mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 18:28:25 +00:00
Tidy up name buffer use in report_addresses().
Buffer may need to be twice MAXDNAME is escaping is enabled in extract_name. The name may include weird characters.
This commit is contained in:
@@ -135,6 +135,13 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_CONNTRACK) && defined(HAVE_UBUS)
|
||||||
|
/* CONNTRACK UBUS code uses this buffer, so if not allocated above,
|
||||||
|
we need to allocate it here. */
|
||||||
|
if (option_bool(OPT_CMARK_ALST_EN) && !daemon->workspacename)
|
||||||
|
daemon->workspacename = safe_malloc(MAXDNAME);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
if (!daemon->lease_file)
|
if (!daemon->lease_file)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -885,6 +885,18 @@ int extract_addresses(struct dns_header *header, size_t qlen, char *name, time_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_CONNTRACK) && defined(HAVE_UBUS)
|
#if defined(HAVE_CONNTRACK) && defined(HAVE_UBUS)
|
||||||
|
/* Don't pass control chars and weird escapes to UBus. */
|
||||||
|
static int safe_name(char *name)
|
||||||
|
{
|
||||||
|
unsigned char *r;
|
||||||
|
|
||||||
|
for (r = (unsigned char *)name; *r; r++)
|
||||||
|
if (!isprint((int)*r))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void report_addresses(struct dns_header *header, size_t len, u32 mark)
|
void report_addresses(struct dns_header *header, size_t len, u32 mark)
|
||||||
{
|
{
|
||||||
unsigned char *p, *endrr;
|
unsigned char *p, *endrr;
|
||||||
@@ -926,10 +938,10 @@ void report_addresses(struct dns_header *header, size_t len, u32 mark)
|
|||||||
{
|
{
|
||||||
if (aqtype == T_CNAME)
|
if (aqtype == T_CNAME)
|
||||||
{
|
{
|
||||||
char namebuff[MAXDNAME];
|
if (!extract_name(header, len, &p, daemon->workspacename, 1, 0))
|
||||||
if (!extract_name(header, len, &p, namebuff, 1, 0))
|
|
||||||
return;
|
return;
|
||||||
ubus_event_bcast_connmark_allowlist_resolved(mark, daemon->namebuff, namebuff, attl);
|
if (safe_name(daemon->namebuff) && safe_name(daemon->workspacename))
|
||||||
|
ubus_event_bcast_connmark_allowlist_resolved(mark, daemon->namebuff, daemon->workspacename, attl);
|
||||||
}
|
}
|
||||||
if (aqtype == T_A)
|
if (aqtype == T_A)
|
||||||
{
|
{
|
||||||
@@ -938,7 +950,7 @@ void report_addresses(struct dns_header *header, size_t len, u32 mark)
|
|||||||
if (ardlen != INADDRSZ)
|
if (ardlen != INADDRSZ)
|
||||||
return;
|
return;
|
||||||
memcpy(&addr, p, ardlen);
|
memcpy(&addr, p, ardlen);
|
||||||
if (inet_ntop(AF_INET, &addr, ip, sizeof ip))
|
if (inet_ntop(AF_INET, &addr, ip, sizeof ip) && safe_name(daemon->namebuff))
|
||||||
ubus_event_bcast_connmark_allowlist_resolved(mark, daemon->namebuff, ip, attl);
|
ubus_event_bcast_connmark_allowlist_resolved(mark, daemon->namebuff, ip, attl);
|
||||||
}
|
}
|
||||||
else if (aqtype == T_AAAA)
|
else if (aqtype == T_AAAA)
|
||||||
@@ -948,7 +960,7 @@ void report_addresses(struct dns_header *header, size_t len, u32 mark)
|
|||||||
if (ardlen != IN6ADDRSZ)
|
if (ardlen != IN6ADDRSZ)
|
||||||
return;
|
return;
|
||||||
memcpy(&addr, p, ardlen);
|
memcpy(&addr, p, ardlen);
|
||||||
if (inet_ntop(AF_INET6, &addr, ip, sizeof ip))
|
if (inet_ntop(AF_INET6, &addr, ip, sizeof ip) && safe_name(daemon->namebuff))
|
||||||
ubus_event_bcast_connmark_allowlist_resolved(mark, daemon->namebuff, ip, attl);
|
ubus_event_bcast_connmark_allowlist_resolved(mark, daemon->namebuff, ip, attl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user