summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2022-09-29 19:57:40 -0400
committerGitHub <noreply@github.com>2022-09-29 16:57:40 -0700
commit43cfdf3822251083b00ddbd0aef1651d8741763f (patch)
tree8558a5e32dfda6a3a7411b540cf4cc46de243016
parent1a7f3b403c9f001db6a52e2f348000e2cadb1c83 (diff)
downloadansible-43cfdf3822251083b00ddbd0aef1651d8741763f.tar.gz
apt module, prevent tb from invalid type for pkg (#78666) (#78908)
* apt module, prevent tb from invalid type for pkg see #78663 (cherry picked from commit 7acd4f75c037974be7fa4e7eabe55152dfc57500)
-rw-r--r--changelogs/fragments/apt_notb.yml2
-rw-r--r--lib/ansible/modules/apt.py10
2 files changed, 9 insertions, 3 deletions
diff --git a/changelogs/fragments/apt_notb.yml b/changelogs/fragments/apt_notb.yml
new file mode 100644
index 0000000000..30d7c41da0
--- /dev/null
+++ b/changelogs/fragments/apt_notb.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - apt module should not traceback on invalid type given as package. issue 78663.
diff --git a/lib/ansible/modules/apt.py b/lib/ansible/modules/apt.py
index 08b3e14729..d37b8d3699 100644
--- a/lib/ansible/modules/apt.py
+++ b/lib/ansible/modules/apt.py
@@ -365,8 +365,8 @@ import time
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.locale import get_best_parsable_locale
from ansible.module_utils.common.respawn import has_respawned, probe_interpreters_for_module, respawn_module
-from ansible.module_utils._text import to_native
-from ansible.module_utils.six import PY3
+from ansible.module_utils._text import to_native, to_text
+from ansible.module_utils.six import PY3, string_types
from ansible.module_utils.urls import fetch_file
DPKG_OPTIONS = 'force-confdef,force-confold'
@@ -617,6 +617,10 @@ def expand_pkgspec_from_fnmatches(m, pkgspec, cache):
new_pkgspec = []
if pkgspec:
for pkgspec_pattern in pkgspec:
+
+ if not isinstance(pkgspec_pattern, string_types):
+ m.fail_json(msg="Invalid type for package name, expected string but got %s" % type(pkgspec_pattern))
+
pkgname_pattern, version_cmp, version = package_split(pkgspec_pattern)
# note that none of these chars is allowed in a (debian) pkgname
@@ -639,7 +643,7 @@ def expand_pkgspec_from_fnmatches(m, pkgspec, cache):
matches = fnmatch.filter(pkg_name_cache, pkgname_pattern)
if not matches:
- m.fail_json(msg="No package(s) matching '%s' available" % str(pkgname_pattern))
+ m.fail_json(msg="No package(s) matching '%s' available" % to_text(pkgname_pattern))
else:
new_pkgspec.extend(matches)
else: