Skip to content

Commit

Permalink
Check input size to avoid a panic (#3521)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferai committed Nov 2, 2017
1 parent 0321a86 commit 87e98dc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
35 changes: 35 additions & 0 deletions builtin/logical/transit/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,3 +1091,38 @@ func testPolicyFuzzingCommon(t *testing.T, be *backend) {
// Wait for them all to finish
wg.Wait()
}

func TestBadInput(t *testing.T) {
var b *backend
sysView := logical.TestSystemView()
storage := &logical.InmemStorage{}

b = Backend(&logical.BackendConfig{
StorageView: storage,
System: sysView,
})

req := &logical.Request{
Storage: storage,
Operation: logical.UpdateOperation,
Path: "keys/test",
}

resp, err := b.HandleRequest(req)
if err != nil {
t.Fatal(err)
}
if resp != nil {
t.Fatal("expected nil response")
}

req.Path = "decrypt/test"
req.Data = map[string]interface{}{
"ciphertext": "vault:v1:abcd",
}

_, err = b.HandleRequest(req)
if err == nil {
t.Fatal("expected error")
}
}
4 changes: 4 additions & 0 deletions helper/keysutil/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ func (p *Policy) Decrypt(context, nonce []byte, value string) (string, error) {
return "", errutil.InternalError{Err: err.Error()}
}

if len(decoded) < gcm.NonceSize() {
return "", errutil.UserError{Err: "invalid ciphertext length"}
}

// Extract the nonce and ciphertext
var ciphertext []byte
if p.ConvergentEncryption && p.ConvergentVersion < 2 {
Expand Down

0 comments on commit 87e98dc

Please sign in to comment.