make spawn function accept slice of &str instead of generics so joining into string for logging is easy
This commit is contained in:
parent
ae3c0a9557
commit
8ea0c31ff6
3 changed files with 10 additions and 8 deletions
|
|
@ -22,7 +22,7 @@ impl FFMpeg {
|
|||
let bitrate = format!("{}k", bitrate);
|
||||
let output = spawn(
|
||||
"ffmpeg",
|
||||
[
|
||||
&[
|
||||
"-i",
|
||||
input_path,
|
||||
"-codec:a",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use core::fmt;
|
||||
use std::ffi::OsStr;
|
||||
use std::process::Output;
|
||||
use std::str::Utf8Error;
|
||||
use tokio::process::Command;
|
||||
use tracing::{event, Level};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SpawnError {
|
||||
|
|
@ -36,11 +36,13 @@ impl fmt::Display for SpawnError {
|
|||
|
||||
/* !!! The argument list could be exploited in a way to inject malicious arguments !!!
|
||||
!!! and alter the way program executes and/or gain access to system !!! */
|
||||
pub async fn spawn<I, S>(program: &str, args: I) -> Result<Output, SpawnError>
|
||||
where
|
||||
I: IntoIterator<Item = S>,
|
||||
S: AsRef<OsStr>,
|
||||
pub async fn spawn(program: &str, args: &[&str]) -> Result<Output, SpawnError>
|
||||
{
|
||||
{
|
||||
let cmd_args = args.join(" ");
|
||||
event!(Level::INFO, "{} {}", program, cmd_args);
|
||||
}
|
||||
|
||||
let output = Command::new(program).args(args).output().await?;
|
||||
|
||||
if !output.status.success() {
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ pub struct YtDlp {}
|
|||
// BUG: REAL ARGUMENT INJECTION! FIX ASAP
|
||||
impl YtDlp {
|
||||
pub async fn load_info(url: &str) -> Result<YtDlpInfo, YtDlpError> {
|
||||
let output = spawn("python", ["-m", "yt_dlp", url, "-j"]).await?;
|
||||
let output = spawn("python", &["-m", "yt_dlp", url, "-j"]).await?;
|
||||
|
||||
Ok(YtDlpInfo::parse(&output.stdout)?)
|
||||
}
|
||||
|
|
@ -178,7 +178,7 @@ impl YtDlp {
|
|||
pub async fn download(url: &str, format_id: &str, output_path: &str) -> Result<(), YtDlpError> {
|
||||
spawn(
|
||||
"python",
|
||||
[
|
||||
&[
|
||||
"-m",
|
||||
"yt_dlp",
|
||||
url,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue