From 791937215d7291db50566ff14a98f56d49881ce2 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 24 Oct 2023 19:10:20 -0700 Subject: [PATCH] stream: escape printed command --- go_vod/stream.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/go_vod/stream.go b/go_vod/stream.go index 5b524315..57be0730 100644 --- a/go_vod/stream.go +++ b/go_vod/stream.go @@ -534,7 +534,18 @@ func (s *Stream) transcode(startId int) { // Start the process s.coder = exec.Command(s.c.FFmpeg, args...) - log.Printf("%s-%s: %s", s.m.id, s.quality, strings.Join(s.coder.Args[:], " ")) + + // Log command, quoting the args as needed + quotedArgs := make([]string, len(s.coder.Args)) + invalidChars := strings.Join([]string{" ", "=", ":", "\"", "\\", "\n", "\t"}, "") + for i, arg := range s.coder.Args { + if strings.ContainsAny(arg, invalidChars) { + quotedArgs[i] = fmt.Sprintf("\"%s\"", arg) + } else { + quotedArgs[i] = arg + } + } + log.Printf("%s-%s: %s", s.m.id, s.quality, strings.Join(quotedArgs[:], " ")) cmdStdOut, err := s.coder.StdoutPipe() if err != nil {