Test for overflow of the capacity value (#9317)
This commit is contained in:
parent
e8ba04f021
commit
57c6ae4233
|
@ -24,6 +24,10 @@ var (
|
|||
|
||||
// ErrBarrierInvalidKey is returned if the Unseal key is invalid
|
||||
ErrBarrierInvalidKey = errors.New("Unseal failed, invalid key")
|
||||
|
||||
// ErrPlaintextTooLarge is returned if a plaintext is offered for encryption
|
||||
// that is too large to encrypt in memory
|
||||
ErrPlaintextTooLarge = errors.New("plaintext value too large")
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -910,6 +910,9 @@ func (b *AESGCMBarrier) encrypt(path string, term uint32, gcm cipher.AEAD, plain
|
|||
// Allocate the output buffer with room for tern, version byte,
|
||||
// nonce, GCM tag and the plaintext
|
||||
capacity := termSize + 1 + gcm.NonceSize() + gcm.Overhead() + len(plain)
|
||||
if capacity < 0 {
|
||||
return nil, ErrPlaintextTooLarge
|
||||
}
|
||||
size := termSize + 1 + gcm.NonceSize()
|
||||
out := make([]byte, size, capacity)
|
||||
|
||||
|
|
Loading…
Reference in New Issue