Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc990e9

Browse files
committed
Closes #16112: platform.architecture does not correctly escape argument to /usr/bin/file
1 parent cf45325 commit fc990e9

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

Lib/platform.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111

112112
__version__ = '1.0.7'
113113

114-
import sys, os, re
114+
import sys, os, re, subprocess
115115

116116
### Globals & Constants
117117

@@ -995,13 +995,15 @@ def _syscmd_file(target,default=''):
995995
if sys.platform in ('dos','win32','win16','os2'):
996996
# XXX Others too ?
997997
return default
998-
target = _follow_symlinks(target).replace('"', '\\"')
998+
target = _follow_symlinks(target)
999999
try:
1000-
f = os.popen('file -b "%s" 2> %s' % (target, DEV_NULL))
1000+
with open(DEV_NULL) as dev_null:
1001+
proc = subprocess.Popen(['file', '-b', '--', target],
1002+
stdout=subprocess.PIPE, stderr=dev_null)
10011003
except (AttributeError,os.error):
10021004
return default
1003-
output = f.read().strip()
1004-
rc = f.close()
1005+
output = proc.stdout.read()
1006+
rc = proc.wait()
10051007
if not output or rc:
10061008
return default
10071009
else:

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Ben Bell
8787
Thomas Bellman
8888
Alexander “Саша” Belopolsky
8989
Eli Bendersky
90+
David Benjamin
9091
Andrew Bennetts
9192
Andy Bensky
9293
Bennett Benson

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ Library
160160
- Issue #15509: webbrowser.UnixBrowser no longer passes empty arguments to
161161
Popen when %action substitutions produce empty strings.
162162

163+
- Issue #16112: platform.architecture does not correctly escape argument to
164+
/usr/bin/file. Patch by David Benjamin.
165+
163166
- Issue #12776,#11839: call argparse type function (specified by add_argument)
164167
only once. Before, the type function was called twice in the case where the
165168
default was specified and the argument was given as well. This was

0 commit comments

Comments
 (0)