Skip to content

Commit 61de406

Browse files
committed
Fix security and stability issues
1 parent 0d0bda6 commit 61de406

3 files changed

Lines changed: 9 additions & 42 deletions

File tree

src/robotide/application/application.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ def restart_ride(args:list):
8181
except Exception as e:
8282
pass
8383
"""
84-
str_args = " ".join(arguments)
85-
subprocess.Popen(str_args, shell=True)
84+
subprocess.Popen(arguments)
8685

8786

8887
class UnthemableWidgetError(Exception):

src/robotide/contrib/testrunner/runprofiles.py

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -326,66 +326,32 @@ def _save_filenames(self):
326326
return clean
327327

328328
def _parse_windows_command(self):
329-
from subprocess import Popen, PIPE
330329
try:
331-
p = Popen(['echo', self.arguments], stdin=PIPE, stdout=PIPE,
332-
stderr=PIPE, shell=True)
333-
output, _ = p.communicate()
334-
from ctypes import cdll
335-
336-
code_page = cdll.kernel32.GetConsoleCP()
337-
if code_page == 0:
338-
os_encoding = os.getenv('RIDE_ENCODING', OUTPUT_ENCODING)
339-
else:
340-
os_encoding = 'cp' + str(code_page)
341-
try:
342-
output = output.decode(os_encoding)
343-
except UnicodeDecodeError:
344-
message_box = RIDEDialog(title="UnicodeDecodeError",
345-
message=f"An UnicodeDecodeError occurred when processing the Arguments."
346-
f" The encoding used was '{os_encoding}'. You may try to define the environment variable"
347-
f" RIDE_ENCODING with a proper value. Other possibility, is to replace 'pythonw.exe' by "
348-
f"'python.exe' in the Desktop Shortcut.", style=wx.OK | wx.ICON_ERROR)
349-
message_box.ShowModal()
350-
output = str(output).lstrip("b\'").lstrip('"').replace('\\r\\n', '').replace('\'', '').\
351-
replace('\\""', '\"').strip()
352-
# print(f"DEBUG: run_profiles _parse_windows_command: output ={output}")
330+
output = self.arguments
353331
even = True
354332
counter = 0
355333
for idx in range(0, len(output)):
356334
if output[idx] == '"':
357335
counter += 1
358336
even = counter % 2 == 0
359-
# print(f"DEBUG: run_profiles loop({idx} counter:{counter}")
360-
self._defined_arguments = output.replace('\'', '')\
361-
.replace('\\\\', '\\').replace('\\r\\n', '')
337+
self._defined_arguments = output.replace('\\\\', '\\')
362338
if not even:
363339
self._defined_arguments = self._defined_arguments.rstrip('"')
364-
except IOError:
340+
except Exception:
365341
pass
366-
367342
def _parse_posix_command(self):
368-
# print(f"DEBUG: run_profiles _parse_posix_command: ENTER self.arguments={self.arguments}")
369-
from subprocess import Popen, PIPE
370343
try:
371-
p = Popen(['echo ' + self.arguments.replace('"', '\\"')], stdin=PIPE, stdout=PIPE,
372-
stderr=PIPE, shell=True)
373-
output, _ = p.communicate()
374-
# print(f"DEBUG: run_profiles _parse_posix_command: RAW output ={output}")
375-
output = str(output).lstrip("b\'").replace('\\n', '').rstrip("\'").strip()
376-
# print(f"DEBUG: run_profiles _parse_posix_command: output ={output}")
344+
output = self.arguments
377345
even = True
378346
counter = 0
379347
for idx in range(0, len(output)):
380348
if output[idx] == '"':
381349
counter += 1
382350
even = counter % 2 == 0
383-
# print(f"DEBUG: run_profiles loop({idx} counter:{counter}")
384-
self._defined_arguments = output.replace('\'', '')\
385-
.replace('\\\\', '\\').replace('\\n', '')
351+
self._defined_arguments = output.replace('\\\\', '\\')
386352
if not even:
387353
self._defined_arguments = self._defined_arguments.rstrip('"')
388-
except IOError:
354+
except Exception:
389355
pass
390356

391357
@staticmethod

src/robotide/run/process.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ def start(self):
4747
self._out_file = open(self._out_path, 'w+b')
4848
if not self._command:
4949
self._error = 'The command is missing from this run configuration.'
50+
self._close_outputs()
5051
return
5152
try:
5253
self._process = subprocess.Popen(self._command, stdout=self._out_fd, stderr=subprocess.STDOUT)
5354
self._pid = self._process.pid
5455
RideRunnerStarted(process=self._pid).publish()
5556
except OSError as err:
5657
self._error = str(err)
58+
self._close_outputs()
5759

5860
def is_finished(self):
5961
return self._error is not None or self._process.poll() is not None

0 commit comments

Comments
 (0)