From e6323433ff69db9594b8e22f79ff25d6c03b2620 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 9 Aug 2021 23:10:03 +0200 Subject: [PATCH] openbsd_pkg: Fix regexp matching crash (#3161) (#3186) When a package name contains special characters (e.g. "g++"), they are interpreted as part of the regexp. This can lead to a crash with an error in the python re module, for instance with "g++": sre_constants.error: multiple repeat Fix this by escaping the package name. Co-authored-by: Baptiste Jonglez (cherry picked from commit 56b5be0630e226f20cf461b2ab9c722de5e34483) Co-authored-by: zorun --- .../fragments/3161-openbsd-pkg-fix-regexp-matching-crash.yml | 2 ++ plugins/modules/packaging/os/openbsd_pkg.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/3161-openbsd-pkg-fix-regexp-matching-crash.yml diff --git a/changelogs/fragments/3161-openbsd-pkg-fix-regexp-matching-crash.yml b/changelogs/fragments/3161-openbsd-pkg-fix-regexp-matching-crash.yml new file mode 100644 index 0000000000..bb29542c04 --- /dev/null +++ b/changelogs/fragments/3161-openbsd-pkg-fix-regexp-matching-crash.yml @@ -0,0 +1,2 @@ +bugfixes: + - openbsd_pkg - fix regexp matching crash. This bug could trigger on package names with special characters, for example ``g++`` (https://github.com/ansible-collections/community.general/pull/3161). diff --git a/plugins/modules/packaging/os/openbsd_pkg.py b/plugins/modules/packaging/os/openbsd_pkg.py index 61e2a5e52b..05c374cb4e 100644 --- a/plugins/modules/packaging/os/openbsd_pkg.py +++ b/plugins/modules/packaging/os/openbsd_pkg.py @@ -241,7 +241,7 @@ def package_present(names, pkg_spec, module): # "file:/local/package/directory/ is empty" message on stderr # while still installing the package, so we need to look for # for a message like "packagename-1.0: ok" just in case. - match = re.search(r"\W%s-[^:]+: ok\W" % pkg_spec[name]['stem'], pkg_spec[name]['stdout']) + match = re.search(r"\W%s-[^:]+: ok\W" % re.escape(pkg_spec[name]['stem']), pkg_spec[name]['stdout']) if match: # It turns out we were able to install the package. @@ -295,7 +295,7 @@ def package_latest(names, pkg_spec, module): pkg_spec[name]['changed'] = False for installed_name in pkg_spec[name]['installed_names']: module.debug("package_latest(): checking for pre-upgrade package name: %s" % installed_name) - match = re.search(r"\W%s->.+: ok\W" % installed_name, pkg_spec[name]['stdout']) + match = re.search(r"\W%s->.+: ok\W" % re.escape(installed_name), pkg_spec[name]['stdout']) if match: module.debug("package_latest(): pre-upgrade package name match: %s" % installed_name)