From fed3e6f67fb16b9c82a9730d5b8b535f22f3bdc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Tue, 15 Jul 2014 17:58:00 +0200 Subject: [PATCH] [fix] Double quote each argument passed to the script in hook_exec --- hook.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hook.py b/hook.py index 9fa4457ed..90ad01d9e 100644 --- a/hook.py +++ b/hook.py @@ -172,9 +172,20 @@ def hook_exec(file, args=None): if "/" in file and file[0:2] != file_path: file_path = os.path.dirname(file) file = file.replace(file_path +"/", "") - msignals.display(m18n.n('executing_script')) + #TODO: Allow python script - p = subprocess.Popen('su - admin -c "cd \\"%s\\" && /bin/bash -x \\"%s\\" %s"' % (file_path, file, ' '.join(arg_list)), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) + + arg_str = '' + if arg_list: + # Concatenate arguments and escape them with double quotes to prevent + # bash related issue if an argument is empty and is not the last + arg_str = '\\"{:s}\\"'.format('\\" \\"'.join(arg_list)) + + msignals.display(m18n.n('executing_script')) + + p = subprocess.Popen('su - admin -c "cd \\"{:s}\\" && ' \ + '/bin/bash -x \\"{:s}\\" {:s}"'.format(file_path, file, arg_str), + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) for line in iter(p.stdout.readline, ''): line = line.rstrip() msignals.display(line, 'log')