Skip to content

[bugfix] Nil pointer deref #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

edznux-dd
Copy link

@edznux-dd edznux-dd commented Jun 25, 2025

Associated issue here: #205.

This PR creates a reproducer and a bug fix for a nil dereference crash:

--- FAIL: TestRegressionNilDeref (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x61ff82]

I believe the nil check need to be done in multiple other places and thus, maybe a more generic solution is warranted, but for the time being, that might be already an improvement :)

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a nil pointer dereference in WhereClause by adding guards in BuildWithFlavor and AddWhereClause, and introduces a regression test to ensure nil receivers don’t panic.

  • Add wc == nil check in BuildWithFlavor
  • Guard against nil wc in AddWhereClause
  • Add TestNilPointerWhere to validate nil receiver safety

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
whereclause.go Added nil checks in BuildWithFlavor and AddWhereClause methods
select_test.go Added TestNilPointerWhere to catch nil receiver panics
Comments suppressed due to low confidence (1)

select_test.go:421

  • [nitpick] This test invokes the build methods but includes no assertions. Add checks on the returned SQL string and args slice to ensure they match expected defaults and to guard against regressions.
func TestNilPointerWhere(t *testing.T) {

@@ -128,6 +128,9 @@ func (wc *WhereClause) AddWhereExpr(args *Args, andExpr ...string) *WhereClause

// AddWhereClause adds all clauses in the whereClause to the wc.
func (wc *WhereClause) AddWhereClause(whereClause *WhereClause) *WhereClause {
if wc == nil {
return nil
Copy link
Preview

Copilot AI Jun 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning nil here may break chaining when the receiver is nil. Consider returning the non-nil whereClause argument (or a new empty WhereClause) to allow fluent calls without panicking or losing the chain.

Suggested change
return nil
return NewWhereClause()

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants