Merge pull request #80 from entireio/fix/checkpoint-nil-deref · Entire
Merge pull request #80 from entireio/fix/checkpoint-nil-deref
11208ab→main·
Soph·1mo ago·2 files·+31 added/-1 removed
Fix nil-pointer panic in checkpoint parent-load error path
Changes
2
internal/planner
Mcheckpoint.go+1/-1
Acheckpoint_test.go+30
50 unmodified lines
51
52
53
54
54
55
56
57
50 unmodified lines
}
commit, err = object.GetCommit(store, parent)
if err != nil {
return nil, fmt.Errorf("load parent commit %s: %w", commit.ParentHashes[0], err)
return nil, fmt.Errorf("load parent commit %s: %w", parent, err)
}
}
// Reverse in-place to get root-to-tip order.
Minternal/planner/checkpoint.go+1/-1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package planner
import (
"strings"
"testing"
git "github.com/go-git/go-git/v6"
"github.com/go-git/go-git/v6/plumbing"
"github.com/go-git/go-git/v6/storage/memory"
)
// When a first-parent is absent from the store, the error path must not
// dereference the (nil) commit it just failed to load, and must name the
// parent hash it could not find.
func TestFirstParentChainStoppingAtMissingParentErrors(t *testing.T) {
repo, err := git.Init(memory.NewStorage(), nil)
if err != nil {
t.Fatalf("init repo: %v", err)
}
missingParent := plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
tip := seedCommit(t, repo, []plumbing.Hash{missingParent})
_, err = FirstParentChainStoppingAt(repo.Storer, tip, map[plumbing.Hash]struct{}{})
if err == nil {
t.Fatal("expected error when first parent is missing from the store")
}
if !strings.Contains(err.Error(), missingParent.String()) {
t.Fatalf("error should name the missing parent %s, got %q", missingParent, err.Error())
}
}