From 95038fa526c8b93e42c59b0735edf1c80b7b6449 Mon Sep 17 00:00:00 2001 From: Jesus Cea Date: Thu, 4 Oct 2012 13:46:33 +0200 Subject: [PATCH] Closes #16112: platform.architecture does not correctly escape argument to /usr/bin/file --- Lib/platform.py | 13 ++++++++----- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Lib/platform.py b/Lib/platform.py index d20c39d9a7c..e94a32aab78 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -113,7 +113,7 @@ __copyright__ = """ __version__ = '1.0.7' -import sys,string,os,re +import sys,string,os,re,subprocess ### Globals & Constants @@ -1023,13 +1023,16 @@ def _syscmd_file(target,default=''): if sys.platform in ('dos','win32','win16','os2'): # XXX Others too ? return default - target = _follow_symlinks(target).replace('"', '\\"') + target = _follow_symlinks(target) try: - f = os.popen('file "%s" 2> %s' % (target, DEV_NULL)) + with open(DEV_NULL) as dev_null: + proc = subprocess.Popen(['file', '-b', '--', target], + stdout=subprocess.PIPE, stderr=dev_null) + except (AttributeError,os.error): return default - output = string.strip(f.read()) - rc = f.close() + output = proc.stdout.read() + rc = proc.wait() if not output or rc: return default else: diff --git a/Misc/ACKS b/Misc/ACKS index b6d375c2093..39bd45040cc 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -77,6 +77,7 @@ Reimer Behrends Ben Bell Thomas Bellman Alexander “Саша” Belopolsky +David Benjamin Andrew Bennetts Andy Bensky Bennett Benson diff --git a/Misc/NEWS b/Misc/NEWS index a02c07393cd..36033eab00d 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -143,6 +143,9 @@ Library io.BytesIO and io.StringIO objects now raise ValueError when the object has been closed. Patch by Alessandro Moura. +- Issue #16112: platform.architecture does not correctly escape argument to + /usr/bin/file. Patch by David Benjamin. + - Issue #12776,#11839: call argparse type function (specified by add_argument) only once. Before, the type function was called twice in the case where the default was specified and the argument was given as well. This was