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:
parent
d407abb50f
commit
d8ea178e69
3 changed files with 15 additions and 0 deletions
6
changelog/unreleased/issue-4975
Normal file
6
changelog/unreleased/issue-4975
Normal 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
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue