From a0125484b47dfbd677a5e425b9a587bfa7662110 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 18 Jul 2016 22:02:39 -0400 Subject: [PATCH] Ensure mount/auth tables are not nil when triggering rollback During setup or teardown there could be a race condition so check for it to avoid a potential panic. --- vault/rollback.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/vault/rollback.go b/vault/rollback.go index 9196783748..4ddf490b9f 100644 --- a/vault/rollback.go +++ b/vault/rollback.go @@ -192,13 +192,21 @@ func (c *Core) startRollback() error { ret := []*MountEntry{} c.mountsLock.RLock() defer c.mountsLock.RUnlock() - for _, entry := range c.mounts.Entries { - ret = append(ret, entry) + // During teardown/setup after a leader change or unseal there could be + // something racy here so make sure the table isn't nil + if c.mounts != nil { + for _, entry := range c.mounts.Entries { + ret = append(ret, entry) + } } c.authLock.RLock() defer c.authLock.RUnlock() - for _, entry := range c.auth.Entries { - ret = append(ret, entry) + // During teardown/setup after a leader change or unseal there could be + // something racy here so make sure the table isn't nil + if c.auth != nil { + for _, entry := range c.auth.Entries { + ret = append(ret, entry) + } } return ret }