1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-21 23:33:03 +00:00

fix panic in fs_reader

This commit is contained in:
textaligncenter 2024-08-03 16:44:45 +00:00
parent d407abb50f
commit d8ea178e69
3 changed files with 15 additions and 0 deletions

View file

@ -0,0 +1,6 @@
Bugfix: Prevent `backup --stdin-from-command` from panicking
If --stdin-from-command is used, restic now checks whether there is a command behind it.
https://github.com/restic/restic/issues/4975
https://github.com/restic/restic/pull/4976

View file

@ -29,6 +29,10 @@ type CommandReader struct {
}
func NewCommandReader(ctx context.Context, args []string, logOutput io.Writer) (*CommandReader, error) {
if len(args) == 0 {
return nil, fmt.Errorf("no command was specified as argument")
}
// Prepare command and stdout
command := exec.CommandContext(ctx, args[0], args[1:]...)
stdout, err := command.StdoutPipe()

View file

@ -34,6 +34,11 @@ func TestCommandReaderInvalid(t *testing.T) {
test.Assert(t, err != nil, "missing error")
}
func TestCommandReaderEmptyArgs(t *testing.T) {
_, err := fs.NewCommandReader(context.TODO(), []string{}, io.Discard)
test.Assert(t, err != nil, "missing error")
}
func TestCommandReaderOutput(t *testing.T) {
reader, err := fs.NewCommandReader(context.TODO(), []string{"echo", "hello world"}, io.Discard)
test.OK(t, err)