From 5a1a1b487eb11c558d264641787909c5b65b5160 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Tue, 16 Jun 2020 13:49:06 +0100 Subject: [PATCH] Dont use byte slices outside of db tx. --- database/database.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/database/database.go b/database/database.go index 146a09c..023c8ea 100644 --- a/database/database.go +++ b/database/database.go @@ -196,7 +196,13 @@ func (vdb *VspDatabase) KeyPair() (ed25519.PrivateKey, ed25519.PublicKey, error) err := vdb.db.View(func(tx *bolt.Tx) error { vspBkt := tx.Bucket(vspBktK) - seed = vspBkt.Get(privateKeyK) + s := vspBkt.Get(privateKeyK) + + // Byte slices returned from Bolt are only valid during a transaction. + // Need to make a copy. + seed = make([]byte, len(s)) + copy(seed, s) + if seed == nil { // should not happen return fmt.Errorf("no private key found") @@ -242,7 +248,12 @@ func (vdb *VspDatabase) GetCookieSecret() ([]byte, error) { err := vdb.db.View(func(tx *bolt.Tx) error { vspBkt := tx.Bucket(vspBktK) - cookieSecret = vspBkt.Get(cookieSecretK) + cs := vspBkt.Get(cookieSecretK) + + // Byte slices returned from Bolt are only valid during a transaction. + // Need to make a copy. + cookieSecret = make([]byte, len(cs)) + copy(cookieSecret, cs) return nil })