Skip to content

Commit

Permalink
db: fix nil pointer dereference in SetContext
Browse files Browse the repository at this point in the history
  • Loading branch information
sumeerbhola committed Nov 7, 2023
1 parent a0b01b6 commit 81d9a4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions level_iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1234,9 +1234,11 @@ func (l *levelIter) SetBounds(lower, upper []byte) {

func (l *levelIter) SetContext(ctx context.Context) {
l.ctx = ctx
// TODO(sumeer): this is losing the ctx = objiotracing.WithLevel(ctx,
// manifest.LevelToInt(opts.level)) that happens in table_cache.go.
l.iter.SetContext(ctx)
if l.iter != nil {
// TODO(sumeer): this is losing the ctx = objiotracing.WithLevel(ctx,
// manifest.LevelToInt(opts.level)) that happens in table_cache.go.
l.iter.SetContext(ctx)
}
}

func (l *levelIter) String() string {
Expand Down
4 changes: 4 additions & 0 deletions merging_iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ func TestMergingIterCornerCases(t *testing.T) {
miter.init(nil /* opts */, &stats, cmp, func(a []byte) int { return len(a) }, levelIters...)
defer miter.Close()
miter.forceEnableSeekOpt = true
// Exercise SetContext for fun
// (https://github.com/cockroachdb/pebble/pull/3037 caused a SIGSEGV due
// to a nil pointer dereference).
miter.SetContext(context.Background())
return runInternalIterCmd(t, d, miter, iterCmdVerboseKey, iterCmdStats(&stats))
default:
return fmt.Sprintf("unknown command: %s", d.Cmd)
Expand Down

0 comments on commit 81d9a4f

Please sign in to comment.