Skip to content

Commit 716f14f

Browse files
authored
py2lcov and xml2lcov: Fix command injection from subprocess.run([..], shell=True, [..]) (fixes #350) (#356)
* xml2lcovutil.py: Extract variable lcov Signed-off-by: Sebastian Pipping <[email protected]> * xml2lcov: Stop allowing command injection via xml2lcovutil.py Signed-off-by: Sebastian Pipping <[email protected]> * py2lcov: Stop allowing command injection Signed-off-by: Sebastian Pipping <[email protected]> --------- Signed-off-by: Sebastian Pipping <[email protected]>
1 parent cea2ab8 commit 716f14f

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

bin/py2lcov

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,12 @@ Example:
191191
while os.path.exists(xml):
192192
xml = base + '.xml%d' % suffix
193193
suffix += 1
194-
cmd = "COVERAGE_FILE='%s' '%s' xml -o '%s'" % (f, args.cover_cmd, xml)
194+
env = os.environ.copy()
195+
env["COVERAGE_FILE"] = f
196+
cmd = [args.cover_cmd, "xml", "-o", xml]
195197
try:
196-
#x = subprocess.run(cmd, capture_output=True, shell=True, check=True)
197-
x = subprocess.run(cmd, shell=True, check=True, stdout=True, stderr=True)
198+
#x = subprocess.run(cmd, capture_output=True, shell=False, check=True, env=env)
199+
x = subprocess.run(cmd, shell=False, check=True, stdout=True, stderr=True, env=env)
198200
except subprocess.CalledProcessError as err:
199201
print("Error: error during XML conversion of %s: %s" % (
200202
f, str(err)));

bin/xml2lcovutil.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,19 @@ def close(self):
121121
self._outf.close()
122122

123123
if self._args.version and None == self._versionScript:
124-
cmd = "'%(lcov)s' -a '%(info)s' -o '%(info)s' --version-script '%(vers)s' %(checksum)s--rc compute_file_version=1 --branch-coverage --ignore inconsistent" % {
125-
'lcov': os.path.join(os.path.split(sys.argv[0])[0], 'lcov'),
126-
'checksum': "--checksum " if self._args.checksum else '',
127-
'info': self._args.output,
128-
'vers' : self._args.version,
129-
}
124+
lcov = os.path.join(os.path.split(sys.argv[0])[0], 'lcov')
125+
cmd = [
126+
lcov,
127+
"-a", self._args.output,
128+
"-o", self._args.output,
129+
"--version-script", self._args.version,
130+
*(["--checksum"] if self._args.checksum else []),
131+
"--rc", "compute_file_version=1",
132+
"--branch-coverage",
133+
"--ignore", "inconsistent",
134+
]
130135
try:
131-
x = subprocess.run(cmd, shell=True, check=True, stdout=True, stderr=True)
136+
x = subprocess.run(cmd, shell=False, check=True, stdout=True, stderr=True)
132137
except subprocess.CalledProcessError as err:
133138
print("Error during lcov version append operation: %s" % (
134139
str(err)))

0 commit comments

Comments
 (0)