aboutsummaryrefslogtreecommitdiff
path: root/yt_dlp/postprocessor/exec.py
diff options
context:
space:
mode:
authorSimon Sawicki <contact@grub4k.xyz>2023-09-24 02:29:01 +0200
committerSimon Sawicki <contact@grub4k.xyz>2023-09-24 02:29:01 +0200
commitde015e930747165dbb8fcd360f8775fd973b7d6e (patch)
tree7588e5aefdba5eb635a8690b824b1a49672342d8 /yt_dlp/postprocessor/exec.py
parent61bdf15fc7400601c3da1aa7a43917310a5bf391 (diff)
[core] Prevent RCE when using `--exec` with `%q` (CVE-2023-40581)
The shell escape function is now using `""` instead of `\"`. `utils.Popen` has been patched to properly quote commands. Prior to this fix using `--exec` together with `%q` when on Windows could cause remote code to execute. See https://github.com/yt-dlp/yt-dlp/security/advisories/GHSA-42h4-v29r-42qg for reference. Authored by: Grub4K
Diffstat (limited to 'yt_dlp/postprocessor/exec.py')
-rw-r--r--yt_dlp/postprocessor/exec.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/yt_dlp/postprocessor/exec.py b/yt_dlp/postprocessor/exec.py
index cfc83167c..c2e73fbab 100644
--- a/yt_dlp/postprocessor/exec.py
+++ b/yt_dlp/postprocessor/exec.py
@@ -1,8 +1,6 @@
-import subprocess
-
from .common import PostProcessor
from ..compat import compat_shlex_quote
-from ..utils import PostProcessingError, encodeArgument, variadic
+from ..utils import Popen, PostProcessingError, variadic
class ExecPP(PostProcessor):
@@ -27,10 +25,10 @@ class ExecPP(PostProcessor):
def run(self, info):
for tmpl in self.exec_cmd:
cmd = self.parse_cmd(tmpl, info)
- self.to_screen('Executing command: %s' % cmd)
- retCode = subprocess.call(encodeArgument(cmd), shell=True)
- if retCode != 0:
- raise PostProcessingError('Command returned error code %d' % retCode)
+ self.to_screen(f'Executing command: {cmd}')
+ _, _, return_code = Popen.run(cmd, shell=True)
+ if return_code != 0:
+ raise PostProcessingError(f'Command returned error code {return_code}')
return [], info