From 6f6e14ee52cb46f76870a8ae0968af88f6f87e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96rjan=20Persson?= Date: Thu, 28 May 2015 20:22:15 +0200 Subject: [PATCH] Fix nil pointer panic when meta bucket is missing If NewQuadStore was called without first calling InitQuadStore, the runtime would panic since the meta bucket never was created. --- graph/bolt/quadstore.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/graph/bolt/quadstore.go b/graph/bolt/quadstore.go index ecc9a81..14fe71c 100644 --- a/graph/bolt/quadstore.go +++ b/graph/bolt/quadstore.go @@ -37,6 +37,10 @@ func init() { } var ( + errNoBucket = errors.New("bolt: bucket is missing") +) + +var ( hashPool = sync.Pool{ New: func() interface{} { return sha1.New() }, } @@ -97,7 +101,9 @@ func newQuadStore(path string, options graph.Options) (graph.QuadStore, error) { return nil, err } err = qs.getMetadata() - if err != nil { + if err == errNoBucket { + panic("bolt: quadstore has not been initialised") + } else if err != nil { return nil, err } return &qs, nil @@ -451,6 +457,9 @@ func (qs *QuadStore) SizeOf(k graph.Value) int64 { func (qs *QuadStore) getInt64ForKey(tx *bolt.Tx, key string, empty int64) (int64, error) { var out int64 b := tx.Bucket(metaBucket) + if b == nil { + return empty, errNoBucket + } data := b.Get([]byte(key)) if data == nil { return empty, nil