mirror of
https://github.com/FiloSottile/age.git
synced 2026-09-05 15:46:55 +00:00
plugin: allow empty prompt responses
Reported by Joe Doyle of Trail of Bits.
This commit is contained in:
+10
-3
@@ -537,7 +537,7 @@ func (p *Plugin) RequestValue(prompt string, secret bool) (string, error) {
|
||||
if s.Type == "fail" {
|
||||
return "", fmt.Errorf("client failed to request value")
|
||||
}
|
||||
if err := expectStanzaWithBody(s, 0); err != nil {
|
||||
if err := expectStanzaWithAnyBody(s, 0); err != nil {
|
||||
return "", p.fatalInteractf("%v", err)
|
||||
}
|
||||
return string(s.Body), nil
|
||||
@@ -596,8 +596,8 @@ func expectStanzaWithNoBody(s *format.Stanza, wantArgs int) error {
|
||||
}
|
||||
|
||||
func expectStanzaWithBody(s *format.Stanza, wantArgs int) error {
|
||||
if len(s.Args) != wantArgs {
|
||||
return fmt.Errorf("%s stanza has %d arguments, want %d", s.Type, len(s.Args), wantArgs)
|
||||
if err := expectStanzaWithAnyBody(s, wantArgs); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(s.Body) == 0 {
|
||||
return fmt.Errorf("%s stanza has 0 bytes of body, want >0", s.Type)
|
||||
@@ -605,6 +605,13 @@ func expectStanzaWithBody(s *format.Stanza, wantArgs int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func expectStanzaWithAnyBody(s *format.Stanza, wantArgs int) error {
|
||||
if len(s.Args) != wantArgs {
|
||||
return fmt.Errorf("%s stanza has %d arguments, want %d", s.Type, len(s.Args), wantArgs)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Plugin) recipientError(idx int, err error) int {
|
||||
if err := p.writeError([]string{"recipient", fmt.Sprint(idx)}, err); err != nil {
|
||||
return p.fatalf("%v", err)
|
||||
|
||||
Reference in New Issue
Block a user