Skip to content

Commit

Permalink
Guard against binary data in /etc/lsb-release on Travis CI (#10, #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Oct 8, 2018
1 parent 37b39ad commit ec3d737
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions executor/contexts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Programmer friendly subprocess wrapper.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: October 7, 2018
# Last Change: October 8, 2018
# URL: https://executor.readthedocs.io

r"""
Expand Down Expand Up @@ -270,12 +270,17 @@ def lsb_release_variables(self):
# instead of one to accomplish the exact same thing :-P.
logger.debug("Trying to read /etc/lsb-release ..")
contents = self.capture('cat', '/etc/lsb-release', check=False, silent=True)
logger.debug("Parsing /etc/lsb-release contents: %r", contents)
for lnum, line in enumerate(contents.splitlines()):
name, delimiter, value = line.partition('=')
name = name.strip()
parsed_value = shlex.split(value)
if len(parsed_value) == 1:
variables[name] = parsed_value[0]
# The zero byte check below guards against a weird edge that has so
# far only manifested in the Python 2.6 environment of Travis CI:
# The parsing of /etc/lsb-release results in the expected variable
# names but values containing binary data including nul bytes.
# https://github.com/xolox/python-executor/issues/15.
if len(parsed_value) == 1 and '\0' not in parsed_value[0]:
variables[name.strip()] = parsed_value[0]
else:
logger.debug("Failed to parse line %i: %r", lnum + 1, line)
if variables:
Expand Down

0 comments on commit ec3d737

Please sign in to comment.