From ecda82bdd3469b385d4320356246b8b01ef60c27 Mon Sep 17 00:00:00 2001 From: renmingshuai Date: Wed, 6 Dec 2023 20:29:43 +0800 Subject: [PATCH] Fix memory leak (cherry picked from commit 52a514a9b3f7fc6c08f9838d2910018e506186cb) --- ...when-using-dhcp-optsfile-with-DHCPv6.patch | 48 ++++++++++ ...duplication-reuse-existing-functions.patch | 91 +++++++++++++++++++ dnsmasq.spec | 11 ++- 3 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 backport-Fix-memory-leak-when-using-dhcp-optsfile-with-DHCPv6.patch create mode 100644 backport-Reduce-code-duplication-reuse-existing-functions.patch diff --git a/backport-Fix-memory-leak-when-using-dhcp-optsfile-with-DHCPv6.patch b/backport-Fix-memory-leak-when-using-dhcp-optsfile-with-DHCPv6.patch new file mode 100644 index 0000000..a18c50a --- /dev/null +++ b/backport-Fix-memory-leak-when-using-dhcp-optsfile-with-DHCPv6.patch @@ -0,0 +1,48 @@ +From d16b995756dc079b1fdc2e63665793979f766a26 Mon Sep 17 00:00:00 2001 +From: renmingshuai +Date: Sat, 30 Sep 2023 23:31:08 +0100 +Subject: [PATCH] Fix memory leak when using --dhcp-optsfile with DHCPv6 + options. + +Conflict:NA +Reference:https://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=commit;h=d16b995756dc079b1fdc2e63665793979f766a26 +--- + src/option.c | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/src/option.c b/src/option.c +index 8322725..286f06b 100644 +--- a/src/option.c ++++ b/src/option.c +@@ -5734,11 +5734,11 @@ static void clear_dynamic_conf(void) + } + } + +-static void clear_dynamic_opt(void) ++static void clear_dhcp_opt(struct dhcp_opt **dhcp_opts) + { + struct dhcp_opt *opts, *cp, **up; + +- for (up = &daemon->dhcp_opts, opts = daemon->dhcp_opts; opts; opts = cp) ++ for (up = dhcp_opts, opts = *dhcp_opts; opts; opts = cp) + { + cp = opts->next; + +@@ -5752,6 +5752,14 @@ static void clear_dynamic_opt(void) + } + } + ++static void clear_dynamic_opt(void) ++{ ++ clear_dhcp_opt(&daemon->dhcp_opts); ++#ifdef HAVE_DHCP6 ++ clear_dhcp_opt(&daemon->dhcp_opts6); ++#endif ++} ++ + void reread_dhcp(void) + { + struct hostsfile *hf; +-- +2.23.0 + diff --git a/backport-Reduce-code-duplication-reuse-existing-functions.patch b/backport-Reduce-code-duplication-reuse-existing-functions.patch new file mode 100644 index 0000000..4416380 --- /dev/null +++ b/backport-Reduce-code-duplication-reuse-existing-functions.patch @@ -0,0 +1,91 @@ +From 10d8b5f001a34ff46b3a72575f3af64b065f8637 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= +Date: Wed, 14 Apr 2021 21:08:31 +0100 +Subject: [PATCH] Reduce code duplication, reuse existing functions + +dhcp_config_free and dhcp_opt_free already implement the same algorithm. +Reuse them. Adds forgotten hostname cleanup to config free. + +Conflict:NA +Reference:https://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=commit;h=10d8b5f001a34ff46b3a72575f3af64b065f8637 +--- + src/option.c | 42 ++++++------------------------------------ + 1 file changed, 6 insertions(+), 36 deletions(-) + +diff --git a/src/option.c b/src/option.c +index e8926a4..23cf058 100644 +--- a/src/option.c ++++ b/src/option.c +@@ -1067,6 +1067,8 @@ static void dhcp_config_free(struct dhcp_config *config) + + if (config->flags & CONFIG_CLID) + free(config->clid); ++ if (config->flags & CONFIG_NAME) ++ free(config->hostname); + + #ifdef HAVE_DHCP6 + if (config->flags & CONFIG_ADDR6) +@@ -5002,30 +5004,8 @@ static void clear_dynamic_conf(void) + + if (configs->flags & CONFIG_BANK) + { +- struct hwaddr_config *mac, *tmp; +- struct dhcp_netid_list *list, *tmplist; +- +- for (mac = configs->hwaddr; mac; mac = tmp) +- { +- tmp = mac->next; +- free(mac); +- } +- +- if (configs->flags & CONFIG_CLID) +- free(configs->clid); +- +- for (list = configs->netid; list; list = tmplist) +- { +- free(list->list); +- tmplist = list->next; +- free(list); +- } +- +- if (configs->flags & CONFIG_NAME) +- free(configs->hostname); +- +- *up = configs->next; +- free(configs); ++ *up = cp; ++ dhcp_config_free(configs); + } + else + up = &configs->next; +@@ -5035,7 +5015,6 @@ static void clear_dynamic_conf(void) + static void clear_dynamic_opt(void) + { + struct dhcp_opt *opts, *cp, **up; +- struct dhcp_netid *id, *next; + + for (up = &daemon->dhcp_opts, opts = daemon->dhcp_opts; opts; opts = cp) + { +@@ -5043,17 +5022,8 @@ static void clear_dynamic_opt(void) + + if (opts->flags & DHOPT_BANK) + { +- if ((opts->flags & DHOPT_VENDOR)) +- free(opts->u.vendor_class); +- free(opts->val); +- for (id = opts->netid; id; id = next) +- { +- next = id->next; +- free(id->net); +- free(id); +- } +- *up = opts->next; +- free(opts); ++ *up = cp; ++ dhcp_opt_free(opts); + } + else + up = &opts->next; +-- +2.23.0 + diff --git a/dnsmasq.spec b/dnsmasq.spec index b8410c0..f2bcf7d 100644 --- a/dnsmasq.spec +++ b/dnsmasq.spec @@ -1,6 +1,6 @@ Name: dnsmasq Version: 2.82 -Release: 13 +Release: 14 Summary: Dnsmasq provides network infrastructure for small networks License: GPLv2 or GPLv3 URL: http://www.thekelleys.org.uk/dnsmasq/ @@ -36,6 +36,8 @@ Patch25: backport-Fix-write-after-free-in-DHCPv6-code-CVE-2022-0934.patch Patch26: backport-Listen-only-on-lo-device-fix-CVE-2020-14312.patch Patch27: backport-CVE-2023-28450-Set-the-default-maximum-DNS-UDP-packet.patch Patch28: backport-Fix-parsing-of-IPv6-addresses-with-peer-from-netlink.patch +Patch29: backport-Reduce-code-duplication-reuse-existing-functions.patch +Patch30: backport-Fix-memory-leak-when-using-dhcp-optsfile-with-DHCPv6.patch BuildRequires: dbus-devel pkgconfig libidn2-devel nettle-devel systemd Requires: nettle >= 3.4 %{name}-help @@ -128,6 +130,13 @@ install -Dpm644 %{SOURCE2} $RPM_BUILD_ROOT%{_sysusersdir}/dnsmasq.conf %{_mandir}/man8/dnsmasq* %changelog +* Wed Dec 6 2023 renmingshuai - 2.82-14 +- Type:bugfix +- Id: +- SUG:NA +- DESC:Reduce code duplication, reuse existing functions + Fix memory leak when using --dhcp-optsfile with DHCPv6 options + * Tue Dec 5 2023 renmingshuai - 2.82-13 - Type:bugfix - Id: -- Gitee