Skip to content

fix(connection): avoid nil pointer panic on socket file stat error#309

Merged
danvergara merged 1 commit into
danvergara:mainfrom
SAY-5:fix-socket-stat-nil-deref
May 25, 2026
Merged

fix(connection): avoid nil pointer panic on socket file stat error#309
danvergara merged 1 commit into
danvergara:mainfrom
SAY-5:fix-socket-stat-nil-deref

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 24, 2026

Copy link
Copy Markdown
Contributor

Description

socketFileExists only returns early when os.Stat fails with an "not exists" error. For any other stat error (for example ENOTDIR when a path component is a regular file, or a permission error), info is nil but the code still calls info.IsDir(), causing a nil pointer dereference panic.

This is reachable from BuildConnectionFromOpts for the MySQL driver when a user passes a --socket path whose parent is not a directory. The fix treats any stat error as "socket does not exist".

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added TestSocketFileExistsStatError, which points the helper at a .sock path that traverses through a regular file (yielding a non-IsNotExist stat error). The test panics on the old code and passes with the fix. Verified with go test -short -race ./pkg/connection/, go vet, and gofmt.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes

@danvergara

Copy link
Copy Markdown
Owner

@SAY-5 Thanks for this fix.
I'll ship it tomorrow morning my time.

@danvergara danvergara merged commit 6a3d968 into danvergara:main May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants