diff options
author | Alexey Yakovenko <waker@users.sourceforge.net> | 2014-03-31 20:07:22 +0200 |
---|---|---|
committer | Alexey Yakovenko <waker@users.sourceforge.net> | 2014-03-31 20:07:42 +0200 |
commit | 4eed226e43370bf4759ed9f655e5fcf0546a9a3c (patch) | |
tree | 7db006a7728441b590b31245db0099b045fd6df0 /plugins/shellexec | |
parent | c7ea2527a763b662fa307905050bd9f777afcf37 (diff) |
shellexec: correct escaping of single quotes
Diffstat (limited to 'plugins/shellexec')
-rw-r--r-- | plugins/shellexec/shellexec.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/plugins/shellexec/shellexec.c b/plugins/shellexec/shellexec.c index 473fc1a7..3894b6b4 100644 --- a/plugins/shellexec/shellexec.c +++ b/plugins/shellexec/shellexec.c @@ -88,6 +88,24 @@ static int shx_exec_track_cmd (Shx_action_t *action, DB_playItem_t *it) { return -1; } strcat (cmd, "&"); + + // replace \' with '"'"' + size_t l = strlen (cmd); + size_t remaining = _POSIX_ARG_MAX - l - 1; + for (int i = 0; cmd[i]; i++) { + if (cmd[i] == '\\' && cmd[i+1] == '\'' && remaining >= 3) { + memmove (&cmd[i+5], &cmd[i+2], l - i + 1 - 2); + memcpy (&cmd[i], "'\"'\"'", 5); + l += 3; + remaining -= 3; + i += 5; + } + else if (remaining < 3) { + fprintf (stderr, "shellexec: command is too long.\n"); + return -1; + } + } + trace ("%s\n", cmd); res = system (cmd); return 0; |