Skip to content

Gazelle buf extension crashes with nil pointer dereference when proto language is not loaded #147

Description

@ctcjab

Description

The buf Gazelle extension crashes with a nil pointer dereference when the proto Gazelle language is not also enabled. This happens because loadConfig in gazelle/buf/config.go:117 calls proto.GetProtoConfig(gazelleConfig) without checking for nil.

Steps to Reproduce

  1. Use aspect_gazelle_prebuilt (or any Gazelle binary with the buf extension compiled in)
  2. Enable buf as a language but not proto:
    aspect_gazelle(
        name = "gazelle",
        languages = [
            "buf",
            "python",
            "starlark",
        ],
    )
  3. Have a buf.yaml in the repo
  4. Run bazelisk run gazelle

Expected Behavior

Gazelle should either:

  • Handle the case gracefully (skip proto-specific config when the proto language isn't loaded), or
  • Emit a clear error message saying that buf requires proto to also be enabled

Actual Behavior

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x24fcdde]

goroutine 1 [running]:
github.com/bufbuild/rules_buf/gazelle/buf.loadConfig(0xf84b825a270, {0xf84b87a74d0, 0x22}, 0xf84b8bda8c0)
	external/rules_buf+/gazelle/buf/config.go:117 +0x47e
github.com/bufbuild/rules_buf/gazelle/buf.(*bufLang).Configure(0x2f5f40?, 0xf84b825a270, {0xf84b87a74d0?, 0x22?}, 0xf84b8bda8c0?)
	external/rules_buf+/gazelle/buf/config.go:65 +0x2d

Root Cause

In gazelle/buf/config.go line 117:

protoConfig := proto.GetProtoConfig(gazelleConfig)
stripImportPrefix := "/" + packageRelativePath
if protoConfig.StripImportPrefix == "" {

proto.GetProtoConfig(gazelleConfig) returns nil when the proto Gazelle language isn't registered, and the subsequent field access panics.

Environment

  • Bazel 9.1.0
  • rules_buf 0.5.4
  • aspect_gazelle_prebuilt 0.0.11
  • buf.yaml v2 format

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions