Skip to content

Commit

Permalink
Backport 1.8: vault-agent: copy values retrieved from bolt (#12534) (#…
Browse files Browse the repository at this point in the history
…12539)

Byte slices returned from Bolt are only valid during a transaction, so
this makes a copy.

Co-authored-by: Tom Proctor <tomhjp@users.noreply.github.com>
  • Loading branch information
tvoran and tomhjp committed Sep 13, 2021
1 parent d26fbf1 commit e99970b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog/12534.txt
@@ -0,0 +1,3 @@
```release-note:bug
agent: Avoid possible `unexpected fault address` panic when using persistent cache.
```
12 changes: 10 additions & 2 deletions command/agent/cache/cacheboltdb/bolt.go
Expand Up @@ -219,7 +219,11 @@ func (b *BoltStorage) GetAutoAuthToken(ctx context.Context) ([]byte, error) {
if meta == nil {
return fmt.Errorf("bucket %q not found", metaBucketName)
}
encryptedToken = meta.Get([]byte(AutoAuthToken))
value := meta.Get([]byte(AutoAuthToken))
if value != nil {
encryptedToken = make([]byte, len(value))
copy(encryptedToken, value)
}
return nil
})
if err != nil {
Expand Down Expand Up @@ -247,7 +251,11 @@ func (b *BoltStorage) GetRetrievalToken() ([]byte, error) {
if keyBucket == nil {
return fmt.Errorf("bucket %q not found", metaBucketName)
}
token = keyBucket.Get([]byte(RetrievalTokenMaterial))
value := keyBucket.Get([]byte(RetrievalTokenMaterial))
if value != nil {
token = make([]byte, len(value))
copy(token, value)
}
return nil
})
if err != nil {
Expand Down

0 comments on commit e99970b

Please sign in to comment.