mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Force null bytes to be str types
When doing membership checks in a string, the string which is being checked will be coerced to unicode if the null byte is a unicode type, leading to a UnicodeDecodeError. This fixes that by forcing the null byte literals to be str types. If the string on which the membership check is being performed is a unicode type, then it will work just fine since a null byte that is a str type will cleanly decode to a unicode type even when the system encoding is ascii.
This commit is contained in:
parent
d3be828696
commit
1024000369
6 changed files with 6 additions and 6 deletions
|
@ -4574,7 +4574,7 @@ def status(cwd,
|
|||
password=password,
|
||||
ignore_retcode=ignore_retcode,
|
||||
output_encoding=output_encoding)['stdout']
|
||||
for line in output.split('\0'):
|
||||
for line in output.split(str('\0')):
|
||||
try:
|
||||
state, filename = line.split(None, 1)
|
||||
except ValueError:
|
||||
|
|
|
@ -2270,7 +2270,7 @@ def managed(name,
|
|||
)
|
||||
|
||||
contents_are_binary = \
|
||||
isinstance(use_contents, six.string_types) and '\0' in use_contents
|
||||
isinstance(use_contents, six.string_types) and str('\0') in use_contents
|
||||
if contents_are_binary:
|
||||
contents = use_contents
|
||||
else:
|
||||
|
|
|
@ -637,7 +637,7 @@ class TCPReqServerChannel(salt.transport.mixins.auth.AESReqServerMixin, salt.tra
|
|||
|
||||
try:
|
||||
id_ = payload['load'].get('id', '')
|
||||
if '\0' in id_:
|
||||
if str('\0') in id_:
|
||||
log.error('Payload contains an id with a null byte: %s', payload)
|
||||
stream.send(self.serial.dumps('bad load: id contains a null byte'))
|
||||
raise tornado.gen.Return()
|
||||
|
|
|
@ -662,7 +662,7 @@ class ZeroMQReqServerChannel(salt.transport.mixins.auth.AESReqServerMixin,
|
|||
|
||||
try:
|
||||
id_ = payload['load'].get('id', '')
|
||||
if '\0' in id_:
|
||||
if str('\0') in id_:
|
||||
log.error('Payload contains an id with a null byte: %s', payload)
|
||||
stream.send(self.serial.dumps('bad load: id contains a null byte'))
|
||||
raise tornado.gen.Return()
|
||||
|
|
|
@ -186,7 +186,7 @@ def is_binary(data):
|
|||
'''
|
||||
if not data or not isinstance(data, six.string_types):
|
||||
return False
|
||||
if '\0' in data:
|
||||
if str('\0') in data:
|
||||
return True
|
||||
|
||||
text_characters = ''.join([chr(x) for x in range(32, 127)] + list('\n\r\t\b'))
|
||||
|
|
|
@ -497,7 +497,7 @@ def valid_id(opts, id_):
|
|||
Returns if the passed id is valid
|
||||
'''
|
||||
try:
|
||||
if any(x in id_ for x in ('/', '\\', '\0')):
|
||||
if any(x in id_ for x in ('/', '\\', str('\0'))):
|
||||
return False
|
||||
return bool(clean_path(opts['pki_dir'], id_))
|
||||
except (AttributeError, KeyError, TypeError):
|
||||
|
|
Loading…
Add table
Reference in a new issue