From f6734839f966ddc783ba6d9659823adfcb062def Mon Sep 17 00:00:00 2001 From: Jendrik Weise Date: Thu, 17 Aug 2023 02:21:52 +0200 Subject: [PATCH] Improve argument quoting using shlex.quote --- rffmpeg | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/rffmpeg b/rffmpeg index ee530c9..376caac 100755 --- a/rffmpeg +++ b/rffmpeg @@ -25,6 +25,7 @@ import logging import os import signal import sys +import shlex import yaml from contextlib import contextmanager @@ -471,16 +472,8 @@ def run_remote_command( stdout = sys.stderr else: stdout = sys.stdout - - # Append all the passed arguments with requoting of any problematic characters - for arg in command_args: - # Escape $ characters - arg = arg.replace('$', '\\$') - # Match bad shell characters: * ' ( ) | [ ] or whitespace - if search("[*'()|\[\]\s]", arg): - rffmpeg_command.append(f'"{arg}"') - else: - rffmpeg_command.append(f"{arg}") + + rffmpeg_command.extend(map(shlex.quote, command_args)) log.info(f"Running command on host '{target_hostname}' ({target_servername})") log.debug(f"Remote command: {' '.join(rffmpeg_ssh_command + rffmpeg_command)}")