summaryrefslogtreecommitdiff
path: root/lib/ansible/modules/get_url.py
diff options
context:
space:
mode:
authorRené Moser <mail@renemoser.net>2021-05-07 16:29:22 +0200
committerGitHub <noreply@github.com>2021-05-07 10:29:22 -0400
commit403a5d147df7261537d5fb37c2474858b96de174 (patch)
tree64ed2df4c6afaa62d27d02aa93ba84918c336e77 /lib/ansible/modules/get_url.py
parent4d7dc15d4e1e214e5091abc554eddb6974b72830 (diff)
downloadansible-403a5d147df7261537d5fb37c2474858b96de174.tar.gz
modules: get_url: Fix checksum binary validation (#74502)
From the sha512sum man page: ... The default mode is to print a line with checksum, a character indicating type ('*' for binary, ' ' for text), and name for each FILE.
Diffstat (limited to 'lib/ansible/modules/get_url.py')
-rw-r--r--lib/ansible/modules/get_url.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/ansible/modules/get_url.py b/lib/ansible/modules/get_url.py
index 572c12c9a6..314f7e1d40 100644
--- a/lib/ansible/modules/get_url.py
+++ b/lib/ansible/modules/get_url.py
@@ -511,14 +511,21 @@ def main():
os.remove(checksum_tmpsrc)
checksum_map = []
for line in lines:
- parts = line.split(None, 1)
+ # Split by one whitespace to keep the leading type char ' ' (whitespace) for text and '*' for binary
+ parts = line.split(" ", 1)
if len(parts) == 2:
- checksum_map.append((parts[0], parts[1]))
+ # Remove the leading type char, we expect
+ if parts[1].startswith((" ", "*",)):
+ parts[1] = parts[1][1:]
+
+ # Append checksum and path without potential leading './'
+ checksum_map.append((parts[0], parts[1].lstrip("./")))
+
filename = url_filename(url)
# Look through each line in the checksum file for a hash corresponding to
# the filename in the url, returning the first hash that is found.
- for cksum in (s for (s, f) in checksum_map if f.strip('./') == filename):
+ for cksum in (s for (s, f) in checksum_map if f == filename):
checksum = cksum
break
else: