From c14e457395403ae3f1125d9dffceb0ee385ce5ec Mon Sep 17 00:00:00 2001 From: Pier Carlo Chiodi Date: Sun, 6 Oct 2019 19:43:50 +0200 Subject: [PATCH 1/6] Prevent unknown escapes in env var from breaking --- pierky/arouteserver/config/base.py | 3 +-- tests/static/test_cfg_general.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pierky/arouteserver/config/base.py b/pierky/arouteserver/config/base.py index d9ff3157..440a4039 100644 --- a/pierky/arouteserver/config/base.py +++ b/pierky/arouteserver/config/base.py @@ -77,8 +77,7 @@ def expand_include(lines): def expand_env_vars(doc): res = doc - for v in os.environ: - res = re.sub("\$\{" + v + "\}", os.environ[v], res) + res = os.path.expandvars(res) res = re.sub("\$\{[A-Za-z0-9_]+\}", "", res) return res diff --git a/tests/static/test_cfg_general.py b/tests/static/test_cfg_general.py index ac45422a..57d3a9f1 100644 --- a/tests/static/test_cfg_general.py +++ b/tests/static/test_cfg_general.py @@ -1411,3 +1411,20 @@ def test_env_vars_corrupted(self): " router_id: ${ROUTER_ID\n" ) self._contains_err("Invalid IPv4 address: ${ROUTER_ID") + + @mock.patch.dict(os.environ, {"ROUTER_ID": "192.0.2.1", "BAD_ESCAPE": r"\u"}) + def test_env_vars_bad_escape(self): + """{}: environment variables: ok (bad escape)""" + + self.cfg._load_from_yaml( + "cfg:\n" + " rs_as: 999\n" + " router_id: ${ROUTER_ID}\n" + " filtering:\n" + " global_black_list_pref: ${GLOBAL_BLACK_LIST_PREF}\n" + ) + self.cfg.parse() + self._contains_err() + + self.assertEqual(self.cfg["router_id"], "192.0.2.1") + self.assertEqual(self.cfg["filtering"]["global_black_list_pref"], None) From 245f05cc92b2c1007b40326e33b1202b73fe63b0 Mon Sep 17 00:00:00 2001 From: Pier Carlo Chiodi Date: Sun, 6 Oct 2019 19:46:46 +0200 Subject: [PATCH 2/6] v0.22.2-alpha1 --- CHANGES.rst | 7 +++++++ pierky/arouteserver/version.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index b5efd82f..c62cd635 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,13 @@ Change log .. note:: **Upgrade notes**: after upgrading, run the ``arouteserver setup-templates`` command to sync the local templates with those distributed with the new version. More details on the `Upgrading `__ section of the documentation. +v0.22.2 +------- + +- Fix: prevent environment variables with unknown escapes (like `\u`) from interrupting the execution. + + Related: `issue #50 on GitHub `_. + v0.22.1 ------- diff --git a/pierky/arouteserver/version.py b/pierky/arouteserver/version.py index 4e5b78be..7fc9d83d 100644 --- a/pierky/arouteserver/version.py +++ b/pierky/arouteserver/version.py @@ -13,5 +13,5 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -__version__ = "0.22.1" # pragma: no cover +__version__ = "0.22.2-alpha1" # pragma: no cover COPYRIGHT_YEAR = 2019 # pragma: no cover From 71d92a1b06b7ca9a645329afa204f2563d7d517a Mon Sep 17 00:00:00 2001 From: Pier Carlo Chiodi Date: Sun, 6 Oct 2019 21:05:12 +0200 Subject: [PATCH 3/6] Use Py3 for latest CentOS installation test --- .travis.yml | 2 +- tests/docker/centos-latest_py2.m4 | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f0d9a023..ef69836f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -66,7 +66,7 @@ jobs: stage: installation tests install: skip script: ./tests/docker/build - env: DISTRO=centos-latest PYVER=2 + env: DISTRO=centos-latest PYVER=3 # Ubuntu, latest - <<: *installation-stage diff --git a/tests/docker/centos-latest_py2.m4 b/tests/docker/centos-latest_py2.m4 index 7667a835..69808380 100644 --- a/tests/docker/centos-latest_py2.m4 +++ b/tests/docker/centos-latest_py2.m4 @@ -4,8 +4,11 @@ include(`base.m4') RUN yum -y update && yum -y install epel-release RUN yum -y update && yum -y install \ - python-pip \ - python-devel \ + python3-pip \ + python3-devel \ gcc +ENV python=python3 +ENV pip=pip3 + include(`install.m4') From fef6f654c10e5420b545e3f5b0c8f64487ac17b3 Mon Sep 17 00:00:00 2001 From: Pier Carlo Chiodi Date: Sun, 6 Oct 2019 21:07:00 +0200 Subject: [PATCH 4/6] v0.22.2-alpha2 --- pierky/arouteserver/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pierky/arouteserver/version.py b/pierky/arouteserver/version.py index 7fc9d83d..46e79f49 100644 --- a/pierky/arouteserver/version.py +++ b/pierky/arouteserver/version.py @@ -13,5 +13,5 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -__version__ = "0.22.2-alpha1" # pragma: no cover +__version__ = "0.22.2-alpha2" # pragma: no cover COPYRIGHT_YEAR = 2019 # pragma: no cover From c160681360fd52573e5b80911df4e78483856bde Mon Sep 17 00:00:00 2001 From: Pier Carlo Chiodi Date: Sun, 6 Oct 2019 21:47:12 +0200 Subject: [PATCH 5/6] Fix filename --- tests/docker/{centos-latest_py2.m4 => centos-latest_py3.m4} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/docker/{centos-latest_py2.m4 => centos-latest_py3.m4} (100%) diff --git a/tests/docker/centos-latest_py2.m4 b/tests/docker/centos-latest_py3.m4 similarity index 100% rename from tests/docker/centos-latest_py2.m4 rename to tests/docker/centos-latest_py3.m4 From b3df9c06c7a4f13c01035a135f77696a0b9de5f3 Mon Sep 17 00:00:00 2001 From: Pier Carlo Chiodi Date: Sun, 6 Oct 2019 21:47:29 +0200 Subject: [PATCH 6/6] v0.22.2-alpha3 --- pierky/arouteserver/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pierky/arouteserver/version.py b/pierky/arouteserver/version.py index 46e79f49..be578d87 100644 --- a/pierky/arouteserver/version.py +++ b/pierky/arouteserver/version.py @@ -13,5 +13,5 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -__version__ = "0.22.2-alpha2" # pragma: no cover +__version__ = "0.22.2-alpha3" # pragma: no cover COPYRIGHT_YEAR = 2019 # pragma: no cover