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)