summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2022-09-28 10:13:00 -0400
committerGitHub <noreply@github.com>2022-09-28 09:13:00 -0500
commit6b8432850f1cac69c3d8588be1514cbff3b1f392 (patch)
tree31ca1d0053e32030a6c5aaa728bb3ca2105b37d5 /lib
parent0747c5c859afee760eebd2457290f491d2f16bbc (diff)
downloadansible-6b8432850f1cac69c3d8588be1514cbff3b1f392.tar.gz
apt module, prevent tb from invalid type for pkg (#78666) (#78907)
* apt module, prevent tb from invalid type for pkg see #78663 (cherry picked from commit 7acd4f75c037974be7fa4e7eabe55152dfc57500)
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/modules/apt.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/ansible/modules/apt.py b/lib/ansible/modules/apt.py
index ac1a0f65b6..1070c30089 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: