Skip to content

[Git HEAD] py2lcov and xml2lcov: Use of subprocess.run([..], shell=True, [..]) allows command injection #350

Closed
@hartwork

Description

@hartwork

For example:

# ./bin/py2lcov 'with spaces'
/bin/sh: line 1: spaces: command not found
Error:  error during XML conversion of with spaces: Command 'COVERAGE_FILE=with spaces coverage xml -o with spaces.xml' returned non-zero exit status 127.

The two places with this problem are:

lcov/bin/py2lcov

Lines 179 to 182 in 34f05f5

cmd = 'COVERAGE_FILE=%s coverage xml -o %s' % (f, xml)
try:
#x = subprocess.run(cmd, capture_output=True, shell=True, check=True)
x = subprocess.run(cmd, shell=True, check=True, stdout=True, stderr=True)

and

lcov/bin/xml2lcovutil.py

Lines 124 to 131 in 34f05f5

cmd = "%(lcov)s -a %(info)s -o %(info)s --version-script '%(vers)s' %(checksum)s--rc compute_file_version=1 --branch-coverage --ignore inconsistent" % {
'lcov': os.path.join(os.path.split(sys.argv[0])[0], 'lcov'),
'checksum': "--checksum " if self._args.checksum else '',
'info': self._args.output,
'vers' : self._args.version,
}
try:
x = subprocess.run(cmd, shell=True, check=True, stdout=True, stderr=True)

Both cases can and should avoid shell=True and be good.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions