1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Ensure ec2_win_password doesn't leak file handle

Currently the module doesn't explicitly close the file handle. This
wraps the reading of the private key in a try/finally block to ensure
the file is properly closed.
This commit is contained in:
Joel Thompson 2015-12-27 16:35:33 -05:00 committed by Matt Clay
parent b92b30e3b3
commit 61672e5c61

View file

@ -144,8 +144,11 @@ def main():
if wait and datetime.datetime.now() >= end:
module.fail_json(msg = "wait for password timeout after %d seconds" % wait_timeout)
f = open(key_file, 'r')
key = RSA.importKey(f.read(), key_passphrase)
try:
f = open(key_file, 'r')
key = RSA.importKey(f.read(), key_passphrase)
finally:
f.close()
cipher = PKCS1_v1_5.new(key)
sentinel = 'password decryption failed!!!'