Description: CVE-2015-8557: Shell injection in FontManager._get_nix_font_path
Origin: backport, https://bitbucket.org/birkenfeld/pygments-main/commits/0036ab1c99e256298094505e5e92f
Bug: https://bitbucket.org/birkenfeld/pygments-main/pull-requests/501/fix-shell-injection-in/diff
Bug-Debian: https://bugs.debian.org/802828
Bug-RedHat: https://bugzilla.redhat.com/show_bug.cgi?id=1276321
Bug-Mageia: https://bugs.mageia.org/show_bug.cgi?id=17331
Forwarded: not-needed
Author: Salvatore Bonaccorso <carnil@debian.org>
Last-Update: 2016-01-10

--- a/pygments/formatters/img.py
+++ b/pygments/formatters/img.py
@@ -15,6 +15,8 @@ from pygments.formatter import Formatter
 from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
     get_choice_opt, xrange
 
+import subprocess
+
 # Import this carefully
 try:
     from PIL import Image, ImageDraw, ImageFont
@@ -75,14 +77,11 @@ class FontManager(object):
             self._create_nix()
 
     def _get_nix_font_path(self, name, style):
-        try:
-            from commands import getstatusoutput
-        except ImportError:
-            from subprocess import getstatusoutput
-        exit, out = getstatusoutput('fc-list "%s:style=%s" file' %
-                                    (name, style))
-        if not exit:
-            lines = out.splitlines()
+        proc = subprocess.Popen(['fc-list', "%s:style=%s" % (name, style), 'file'],
+                                stdout=subprocess.PIPE, stderr=None)
+        stdout, _ = proc.communicate()
+        if proc.returncode == 0:
+            lines = stdout.splitlines()
             if lines:
                 path = lines[0].strip().strip(':')
                 return path
