]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Use shell in local cmd_execute() only if needed
authorJouni Malinen <j@w1.fi>
Mon, 27 Jun 2016 17:10:23 +0000 (20:10 +0300)
committerJouni Malinen <j@w1.fi>
Mon, 27 Jun 2016 18:10:35 +0000 (21:10 +0300)
The generic cmd_execute() function was introduced in a manner that
converted the argument array to a string and used shell to run the
command unconditionally. This is not really desirable, so move back to
using the command array by default and use the single command string
with a shell only when really needed.

Signed-off-by: Jouni Malinen <j@w1.fi>
tests/hwsim/hostapd.py
tests/hwsim/test_ap_ciphers.py
tests/hwsim/wpasupplicant.py

index 9d670768b9a1a98198c135056a6858266ffa1c88..51ad02e179de5b9990b98506151f8eb39b66b898 100644 (file)
@@ -42,11 +42,14 @@ class HostapdGlobal:
             self.dbg = hostname + "/" + str(port)
         self.mon.attach()
 
-    def cmd_execute(self, cmd_array):
+    def cmd_execute(self, cmd_array, shell=False):
         if self.hostname is None:
-            cmd = ' '.join(cmd_array)
+            if shell:
+                cmd = ' '.join(cmd_array)
+            else:
+                cmd = cmd_array
             proc = subprocess.Popen(cmd, stderr=subprocess.STDOUT,
-                                    stdout=subprocess.PIPE, shell=True)
+                                    stdout=subprocess.PIPE, shell=shell)
             out = proc.communicate()[0]
             ret = proc.returncode
             return ret, out
@@ -146,14 +149,14 @@ class Hostapd:
         self.bssid = None
         self.bssidx = bssidx
 
-    def cmd_execute(self, cmd_array):
+    def cmd_execute(self, cmd_array, shell=False):
         if self.hostname is None:
-            cmd = ""
-            for arg in cmd_array:
-                cmd += arg + " "
-            cmd = cmd.strip()
+            if shell:
+                cmd = ' '.join(cmd_array)
+            else:
+                cmd = cmd_array
             proc = subprocess.Popen(cmd, stderr=subprocess.STDOUT,
-                                    stdout=subprocess.PIPE, shell=True)
+                                    stdout=subprocess.PIPE, shell=shell)
             out = proc.communicate()[0]
             ret = proc.returncode
             return ret, out
@@ -588,6 +591,6 @@ def ht40_minus_params(channel="1", ssid=None, country=None):
     params['ht_capab'] = "[HT40-]"
     return params
 
-def cmd_execute(apdev, cmd):
+def cmd_execute(apdev, cmd, shell=False):
     hapd_global = HostapdGlobal(apdev)
-    return hapd_global.cmd_execute(cmd)
+    return hapd_global.cmd_execute(cmd, shell=shell)
index cbb2b2feb52a76db66130411bc19afd3de39270d..1d7877cb5e697f340319bb3252b49b187c627930 100644 (file)
@@ -86,12 +86,14 @@ def test_ap_cipher_tkip_countermeasures_ap(dev, apdev):
                    pairwise="TKIP", group="TKIP", scan_freq="2412")
 
     dev[0].dump_monitor()
-    dev[0].cmd_execute([ "echo", "-n", apdev[0]['bssid'], ">", testfile ])
+    dev[0].cmd_execute([ "echo", "-n", apdev[0]['bssid'], ">", testfile ],
+                       shell=True)
     ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
     if ev is not None:
         raise Exception("Unexpected disconnection on first Michael MIC failure")
 
-    dev[0].cmd_execute([ "echo", "-n", "ff:ff:ff:ff:ff:ff", ">", testfile ])
+    dev[0].cmd_execute([ "echo", "-n", "ff:ff:ff:ff:ff:ff", ">", testfile ],
+                       shell=True)
     ev = dev[0].wait_disconnected(timeout=10,
                                   error="No disconnection after two Michael MIC failures")
     if "reason=14" not in ev:
@@ -118,12 +120,14 @@ def test_ap_cipher_tkip_countermeasures_sta(dev, apdev):
                    pairwise="TKIP", group="TKIP", scan_freq="2412")
 
     dev[0].dump_monitor()
-    hapd.cmd_execute([ "echo", "-n", dev[0].own_addr(), ">", testfile ])
+    hapd.cmd_execute([ "echo", "-n", dev[0].own_addr(), ">", testfile ],
+                     shell=True)
     ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
     if ev is not None:
         raise Exception("Unexpected disconnection on first Michael MIC failure")
 
-    hapd.cmd_execute([ "echo", "-n", "ff:ff:ff:ff:ff:ff", ">", testfile ])
+    hapd.cmd_execute([ "echo", "-n", "ff:ff:ff:ff:ff:ff", ">", testfile ],
+                     shell=True)
     ev = dev[0].wait_disconnected(timeout=10,
                                   error="No disconnection after two Michael MIC failures")
     if "reason=14 locally_generated=1" not in ev:
index 1f456905b37d84a5a93bbd32f8cb68df9f4c5f6a..a62a209bce8399049ea8182cf171a60523aca958 100644 (file)
@@ -49,11 +49,14 @@ class WpaSupplicant:
         else:
             self.global_mon = None
 
-    def cmd_execute(self, cmd_array):
+    def cmd_execute(self, cmd_array, shell=False):
         if self.hostname is None:
-            cmd = ' '.join(cmd_array)
+            if shell:
+                cmd = ' '.join(cmd_array)
+            else:
+                cmd = cmd_array
             proc = subprocess.Popen(cmd, stderr=subprocess.STDOUT,
-                                    stdout=subprocess.PIPE, shell=True)
+                                    stdout=subprocess.PIPE, shell=shell)
             out = proc.communicate()[0]
             ret = proc.returncode
             return ret, out