-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
openbsd_pkg: Fix regexp matching crash #3161
openbsd_pkg: Fix regexp matching crash #3161
Conversation
This bug is present since the beginning of this repo (I haven't checked in the previous ansible repo), so it would be nice to backport the fix to stable releases if it makes sense. |
Hello @zorun, thanks for reporting this issue! It indeed looks like a bug and your fix looks good from a cursory review. I’ll get back to you when I have been able to properly review and test this locally 🙂. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a changelog fragment. Unit tests for this fix would be nice as well to demonstrate it's effectiveness and avoid future regressions. If you don't want to write tests for the full package_present
and package_latest
functions I would wrap these regex tests into functions which just return a bool
based on the search result. And since the last feature was added in community,general 1.3.0 I don't think backporting will be an issue. Thanks!
Thanks! If you want to reproduce, I should mention that I triggered this bug when the package is not found. It triggered while trying to install |
ce44aac
to
9442bba
Compare
I added a changelog entry, thanks for the pointer. About tests, I didn't find any existing unit test for openbsd_pkg. Do you have pointers to documentation or a simple test I could use as a template? |
changelogs/fragments/3161-openbsd-pkg-fix-regexp-matching-crash.yml
Outdated
Show resolved
Hide resolved
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.
9442bba
to
71ef31f
Compare
The |
FYI: 3.5.0 and 2.5.5 will be released tomorrow. @eest if you can confirm that this fix works by then, I'll gladly include it even if there are no tests yet. (The change looks safe enough to me that it's ok to add the tests later.) |
Thanks for the pointer, I don't have access to a
... and after your fix:
A clear improvement 🙂 . As for the other instance you fixed, given that
... and again with the fix:
I have verified upgrades still work as expected by installing
Since the module documentation at https://docs.ansible.com/ansible/latest/collections/community/general/openbsd_pkg_module.html states As for why there are no tests in the code I think this is because the majority of this module was written at a time when there was no testing infrastructure in place (at least that I was aware about). I have run the fixed verson of the code through my own testing playbook at https://github.com/eest/openbsd_pkg-tests which succeeded. @felixfontein you have my OK to merge this PR. |
Backport to stable-2: 💚 backport PR created✅ Backport PR branch: Backported as #3185 🤖 @patchback |
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 <git@bitsofnetworks.org> (cherry picked from commit 56b5be0)
Backport to stable-3: 💚 backport PR created✅ Backport PR branch: Backported as #3186 🤖 @patchback |
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 <git@bitsofnetworks.org> (cherry picked from commit 56b5be0)
@zorun thanks a lot for fixing this! |
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 <git@bitsofnetworks.org> (cherry picked from commit 56b5be0) Co-authored-by: zorun <github@bitsofnetworks.org>
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 <git@bitsofnetworks.org> (cherry picked from commit 56b5be0) Co-authored-by: zorun <github@bitsofnetworks.org>
Excellent, thanks for the in-depth review @eest ! |
SUMMARY
Fix regexp crash caused by missing escaping of package name.
ISSUE TYPE
COMPONENT NAME
openbsd_pkg
ADDITIONAL INFORMATION
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++":
Fix this by escaping the package name.