plugin: reject negative file indexes

Reported by Joe Doyle of Trail of Bits.
This commit is contained in:
Filippo Valsorda
2026-08-29 19:30:10 +02:00
parent e8d1b2f216
commit 352cb3e133
2 changed files with 20 additions and 0 deletions
+17
View File
@@ -67,6 +67,23 @@ func (testPQCRecipient) WrapWithLabels(fileKey []byte) ([]*age.Stanza, []string,
return []*age.Stanza{{Type: "test", Body: fileKey}}, []string{"postquantum"}, nil
}
func TestIdentityV1NegativeIndex(t *testing.T) {
p, err := New("test")
if err != nil {
t.Fatal(err)
}
p.HandleIdentity(func([]byte) (age.Identity, error) { return nil, nil })
stderr := &bytes.Buffer{}
p.SetIO(strings.NewReader("-> recipient-stanza -1 X25519\n\n"), io.Discard, stderr)
if code := p.IdentityV1(); code != 1 {
t.Errorf("exit code = %d, want 1", code)
}
want := "unexpected file index -1, previous was -1"
if got := stderr.String(); got != want {
t.Errorf("stderr = %q, want %q", got, want)
}
}
func TestLabels(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Windows support is TODO")
+3
View File
@@ -399,6 +399,9 @@ ReadLoop:
if err != nil {
return p.fatalf("failed to parse recipient-stanza stanza argument: %v", err)
}
if i < 0 {
return p.fatalf("unexpected file index %d, previous was %d", i, len(files)-1)
}
ss := &age.Stanza{Type: s.Args[1], Args: s.Args[2:], Body: s.Body}
switch i {
case len(files):