From 073c5f87e54682284b0d213147af8a8381f3e30a Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Fri, 17 Sep 2021 10:57:18 +0200 Subject: [PATCH] Remove dhcp_extra_opt name after first newline character Passing newline as extra dhcp option name to the DHCP agent causes issues with configuration of the dnsmasq process for the network. This patch removes everything what is after first newline character in the dhcp_extra_opt's name before building dnsmasq's config. Closes-bug: #1943930 Change-Id: Iab2832e750ff5ef09c5dcacae4dbff4f9e62bc2d (cherry picked from commit 5abd1fb61018e497b369712a0952bb1a18022142) --- neutron/agent/linux/dhcp.py | 1 + neutron/tests/unit/agent/linux/test_dhcp.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index 8e247adb240..dd10d5e1e46 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -1307,6 +1307,7 @@ class Dnsmasq(DhcpLocalProcess): def _format_option(self, ip_version, tag, option, *args): """Format DHCP option by option name or code.""" option = str(option) + option = option.split("\n", 1)[0] pattern = "(tag:(.*),)?(.*)$" matches = re.match(pattern, option) extra_tag = matches.groups()[0] diff --git a/neutron/tests/unit/agent/linux/test_dhcp.py b/neutron/tests/unit/agent/linux/test_dhcp.py index 75552ec2312..21ff1e5a264 100644 --- a/neutron/tests/unit/agent/linux/test_dhcp.py +++ b/neutron/tests/unit/agent/linux/test_dhcp.py @@ -231,7 +231,7 @@ class FakeV6PortExtraOpt(object): DhcpOpt(opt_name='dns-server', opt_value='ffea:3ba5:a17a:4ba3::100', ip_version=constants.IP_VERSION_6), - DhcpOpt(opt_name='malicious-option', + DhcpOpt(opt_name='malicious-option\nwith-new-line', opt_value='aaa\nbbb.ccc\n', ip_version=constants.IP_VERSION_6)]