File system-config-printer-subprocess-no-shell.patch of Package system-config-printer

From 08dac9a6bc423166ee5593b56aa29a51c0b61584 Mon Sep 17 00:00:00 2001
From: Vincent Untz <vuntz@opensuse.org>
Date: Thu, 8 Dec 2011 10:24:24 +0100
Subject: [PATCH] Always use a sequence as args for timedops.TimedSubprocess()

This helps make sure there is never an issue where we forget to escape a
string.

See https://bugzilla.novell.com/show_bug.cgi?id=735322

Index: system-config-printer-1.2.0/system-config-printer.py
===================================================================
--- system-config-printer-1.2.0.orig/system-config-printer.py
+++ system-config-printer-1.2.0/system-config-printer.py
@@ -4774,11 +4774,13 @@ class NewPrinterGUI(GtkGUI):
         self.add_devices (result, current_uri, no_more=True)
 
     def get_hpfax_device_id(self, faxuri):
-        os.environ["URI"] = faxuri
-        cmd = 'LC_ALL=C DISPLAY= hp-info -x -i -d"${URI}"'
-        debugprint (faxuri + ": " + cmd)
+        new_environ = os.environ.copy()
+        new_environ['LC_ALL'] = "C"
+        new_environ['DISPLAY'] = ""
+        args = ["hp-info", "-x", "-i", "-d" + faxuri]
+        debugprint (faxuri + ": " + str(args))
         try:
-            p = subprocess.Popen (cmd, shell=True,
+            p = subprocess.Popen (args, env=new_environ,
                                   stdin=file("/dev/null"),
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
@@ -4805,15 +4807,14 @@ class NewPrinterGUI(GtkGUI):
             return 'MFG:HP;MDL:Fax;DES:HP Fax;'
 
     def get_hplip_uri_for_network_printer(self, host, mode):
-        os.environ["HOST"] = host
         if mode == "print": mod = "-c"
         elif mode == "fax": mod = "-f"
         else: mod = "-c"
-        cmd = 'hp-makeuri ' + mod + ' "${HOST}"'
-        debugprint (host + ": " + cmd)
+        args = ["hp-makeuri", mod, host]
+        debugprint (host + ": " + str(args))
         uri = None
         try:
-            p = subprocess.Popen (cmd, shell=True,
+            p = subprocess.Popen (args,
                                   stdin=file("/dev/null"),
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
@@ -4849,12 +4850,11 @@ class NewPrinterGUI(GtkGUI):
                 host = device.uri[s:s+e]
         # Try to get make and model via SNMP
         if host:
-            os.environ["HOST"] = host
-            cmd = '/usr/lib/cups/backend/snmp "${HOST}"'
-            debugprint (host + ": " + cmd)
+            args = ["/usr/lib/cups/backend/snmp", host]
+            debugprint (host + ": " + str(args))
             stdout = None
             try:
-                p = subprocess.Popen (cmd, shell=True,
+                p = subprocess.Popen (args,
                                       stdin=file("/dev/null"),
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)
Index: system-config-printer-1.2.0/troubleshoot/CheckPrinterSanity.py
===================================================================
--- system-config-printer-1.2.0.orig/troubleshoot/CheckPrinterSanity.py
+++ system-config-printer-1.2.0/troubleshoot/CheckPrinterSanity.py
@@ -80,16 +80,17 @@ class CheckPrinterSanity(Question):
             elif scheme == "smb":
                 u = smburi.SMBURI (uri)
                 (group, host, share, user, password) = u.separate ()
-                os.environ['HOST'] = host
+                new_environ = os.environ.copy()
+                new_environ['LC_ALL'] = "C"
                 if group:
-                    os.environ['GROUP'] = group
-                    cmdline = 'LC_ALL=C nmblookup -W "$GROUP" "$HOST"'
+                    args = ["nmblookup", "-W", group, host]
                 else:
-                    cmdline = 'LC_ALL=C nmblookup "$HOST"'
+                    args = ["nmblookup", host]
                 try:
                     p = TimedSubprocess (parent=parent,
                                          timeout=5000,
-                                         args=cmdline, shell=True,
+                                         args=args,
+                                         env=new_environ,
                                          stdin=file("/dev/null"),
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE)
@@ -108,12 +109,14 @@ class CheckPrinterSanity(Question):
                     # Problem executing command.
                     pass
             elif scheme == "hp":
-                os.environ['URI'] = uri
+                new_environ = os.environ.copy()
+                new_environ['LC_ALL'] = "C"
+                new_environ['DISPLAY'] = ""
                 try:
                     p = TimedSubprocess (parent=parent,
                                          timeout=3000,
-                                         args='LC_ALL=C DISPLAY= hp-info -d"$URI"',
-                                         shell=True,
+                                         args=["hp-info", "-d" + uri],
+                                         env=new_environ,
                                          stdin=file("/dev/null"),
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE)
Index: system-config-printer-1.2.0/troubleshoot/CheckUSBPermissions.py
===================================================================
--- system-config-printer-1.2.0.orig/troubleshoot/CheckUSBPermissions.py
+++ system-config-printer-1.2.0/troubleshoot/CheckUSBPermissions.py
@@ -56,12 +56,15 @@ class CheckUSBPermissions(Question):
         if not os.access (GETFACL, os.X_OK):
             return False
 
+        new_environ = os.environ.copy()
+        new_environ['LC_ALL'] = "C"
+
         # Run lsusb
         parent = self.troubleshooter.get_window ()
         try:
             self.op = TimedSubprocess (parent=parent,
-                                       args="LC_ALL=C " + LSUSB + " -v",
-                                       shell=True,
+                                       args=[LSUSB, "-v"],
+                                       env=new_environ,
                                        stdin=file("/dev/null"),
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)
@@ -139,9 +142,8 @@ class CheckUSBPermissions(Question):
         for path in paths:
             try:
                 self.op = TimedSubprocess (parent=parent,
-                                           args="LC_ALL=C %s %s" % (GETFACL,
-                                                                    path),
-                                           shell=True,
+                                           args=[GETFACL, path],
+                                           env=new_environ,
                                            stdin=file("/dev/null"),
                                            stdout=subprocess.PIPE,
                                            stderr=subprocess.PIPE)
openSUSE Build Service is sponsored by