Skip to content

Commit

Permalink
Fix Command Injection Vulnerability (#1778)
Browse files Browse the repository at this point in the history
* Added fix for command injection

* changed function name from sh to runCommand
  • Loading branch information
ouxs-19 authored Feb 29, 2024
1 parent c1966af commit 31a4c9c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions backend/go/transcribe/transcript.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ import (
"github.com/go-skynet/LocalAI/core/schema"
)

func sh(c string) (string, error) {
cmd := exec.Command("/bin/sh", "-c", c)
func runCommand(command []string) (string, error) {
cmd := exec.Command(command[0], command[1:]...)
cmd.Env = os.Environ()
o, err := cmd.CombinedOutput()
return string(o), err
out, err := cmd.CombinedOutput()
return string(out), err
}

// AudioToWav converts audio to wav for transcribe. It bashes out to ffmpeg
// AudioToWav converts audio to wav for transcribe.
// TODO: use https://github.com/mccoyst/ogg?
func audioToWav(src, dst string) error {
out, err := sh(fmt.Sprintf("ffmpeg -i %s -format s16le -ar 16000 -ac 1 -acodec pcm_s16le %s", src, dst))
command := []string{"ffmpeg", "-i", src, "-format", "s16le", "-ar", "16000", "-ac", "1", "-acodec", "pcm_s16le", dst}
out, err := runCommand(command)
if err != nil {
return fmt.Errorf("error: %w out: %s", err, out)
}

return nil
}

Expand Down

0 comments on commit 31a4c9c

Please sign in to comment.