Merge pull request #4976 from textaligncenter/backup-panic

fix panic in fs_reader
This commit is contained in:
Michael Eischer 2024-08-03 19:56:15 +00:00 committed by GitHub
commit a48baf6f3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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)