@@ -101,15 +101,18 @@ def inspect_interface(interface_name):
101101 status = InterfaceStatus (interface_name , False , None , None )
102102
103103 try :
104- ip_cmd_out_raw = subprocess .check_output ([
105- 'ip' ,
106- '-json' ,
107- 'address' ,
108- 'show' ,
109- interface_name ,
110- ],
111- stderr = subprocess .STDOUT ,
112- universal_newlines = True )
104+ # The command arguments are trusted because they aren't based on user
105+ # input.
106+ ip_cmd_out_raw = subprocess .check_output ( # noqa: S603
107+ [
108+ '/usr/bin/ip' ,
109+ '-json' ,
110+ 'address' ,
111+ 'show' ,
112+ interface_name ,
113+ ],
114+ stderr = subprocess .STDOUT ,
115+ universal_newlines = True )
113116 except subprocess .CalledProcessError as e :
114117 logger .error ('Failed to run `ip` command: %s' , str (e ))
115118 return status
@@ -148,7 +151,8 @@ def determine_wifi_settings():
148151 # We cannot read the wpa_supplicant.conf file directly, because it is
149152 # owned by the root user.
150153 config_lines = subprocess .check_output ([
151- 'sudo' , '/opt/tinypilot-privileged/scripts/print-marker-sections' ,
154+ '/usr/bin/sudo' ,
155+ '/opt/tinypilot-privileged/scripts/print-marker-sections' ,
152156 '/etc/wpa_supplicant/wpa_supplicant.conf'
153157 ],
154158 stderr = subprocess .STDOUT ,
@@ -181,19 +185,22 @@ def enable_wifi(wifi_settings):
181185 Raises:
182186 NetworkError
183187 """
188+ # The command arguments are trusted because the WiFi settings are validated
189+ # by the caller.
184190 args = [
185- 'sudo' , '/opt/tinypilot-privileged/scripts/enable-wifi' , '--country ' ,
186- wifi_settings .country_code , '--ssid' , wifi_settings .ssid
191+ '/usr/bin/ sudo' , '/opt/tinypilot-privileged/scripts/enable-wifi' ,
192+ '--country' , wifi_settings .country_code , '--ssid' , wifi_settings .ssid
187193 ]
188194 try :
189195 # Ignore pylint since we're not managing the child process.
190196 # pylint: disable=consider-using-with
191197 if wifi_settings .psk :
192198 args .append ('--psk' )
193- process = subprocess .Popen (args , stdin = subprocess .PIPE , text = True )
199+ process = subprocess .Popen ( # noqa: S603
200+ args , stdin = subprocess .PIPE , text = True )
194201 process .communicate (input = wifi_settings .psk )
195202 else :
196- subprocess .Popen (args )
203+ subprocess .Popen (args ) # noqa: S603
197204
198205 except subprocess .CalledProcessError as e :
199206 raise NetworkError (str (e .output ).strip ()) from e
@@ -212,7 +219,7 @@ def disable_wifi():
212219 # Ignore pylint since we're not managing the child process.
213220 # pylint: disable=consider-using-with
214221 subprocess .Popen ([
215- 'sudo' ,
222+ '/usr/bin/ sudo' ,
216223 '/opt/tinypilot-privileged/scripts/disable-wifi' ,
217224 ])
218225 except subprocess .CalledProcessError as e :
0 commit comments