mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #46966 from terminalmage/issue46934
Fix traceback when attempting to decode binary data to unicode
This commit is contained in:
commit
58f59cfbff
@ -141,7 +141,11 @@ class Serial(object):
|
||||
# Due to this, if we don't need it, don't pass it at all so
|
||||
# that under Python 2 we can still work with older versions
|
||||
# of msgpack.
|
||||
ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_decoder, encoding=encoding)
|
||||
try:
|
||||
ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_decoder, encoding=encoding)
|
||||
except UnicodeDecodeError:
|
||||
# msg contains binary data
|
||||
ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_decoder)
|
||||
else:
|
||||
ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_decoder)
|
||||
if six.PY3 and encoding is None and not raw:
|
||||
|
@ -738,7 +738,7 @@ class Pillar(object):
|
||||
msg = 'Rendering SLS \'{0}\' failed, render error:\n{1}'.format(
|
||||
sls, exc
|
||||
)
|
||||
log.critical(msg)
|
||||
log.critical(msg, exc_info=True)
|
||||
if self.opts.get('pillar_safe_render_error', True):
|
||||
errors.append(
|
||||
'Rendering SLS \'{0}\' failed. Please see master log for '
|
||||
|
@ -269,16 +269,22 @@ def _decrypt_ciphertext(cipher, translate_newlines=False):
|
||||
decrypted, log the error, and return the ciphertext back out.
|
||||
'''
|
||||
if translate_newlines:
|
||||
cipher = cipher.replace(r'\n', '\n')
|
||||
if six.PY3:
|
||||
cipher = cipher.encode(__salt_system_encoding__)
|
||||
try:
|
||||
cipher = salt.utils.stringutils.to_unicode(cipher).replace(r'\n', '\n')
|
||||
except UnicodeDecodeError:
|
||||
# ciphertext is binary
|
||||
pass
|
||||
cipher = salt.utils.stringutils.to_bytes(cipher)
|
||||
cmd = [_get_gpg_exec(), '--homedir', _get_key_dir(), '--status-fd', '2',
|
||||
'--no-tty', '-d']
|
||||
proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=False)
|
||||
decrypted_data, decrypt_error = proc.communicate(input=cipher)
|
||||
if not decrypted_data:
|
||||
if six.PY3:
|
||||
cipher = cipher.decode(__salt_system_encoding__)
|
||||
try:
|
||||
cipher = salt.utils.stringutils.to_unicode(cipher)
|
||||
except UnicodeDecodeError:
|
||||
# decrypted data contains undecodable binary data
|
||||
pass
|
||||
log.warning(
|
||||
'Could not decrypt cipher %s, received: %s',
|
||||
cipher,
|
||||
@ -286,9 +292,12 @@ def _decrypt_ciphertext(cipher, translate_newlines=False):
|
||||
)
|
||||
return cipher
|
||||
else:
|
||||
if six.PY3 and isinstance(decrypted_data, bytes):
|
||||
decrypted_data = decrypted_data.decode(__salt_system_encoding__)
|
||||
return six.text_type(decrypted_data)
|
||||
try:
|
||||
decrypted_data = salt.utils.stringutils.to_unicode(decrypted_data)
|
||||
except UnicodeDecodeError:
|
||||
# decrypted data contains undecodable binary data
|
||||
pass
|
||||
return decrypted_data
|
||||
|
||||
|
||||
def _decrypt_object(obj, translate_newlines=False):
|
||||
|
Loading…
Reference in New Issue
Block a user