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
- Use
aspect_gazelle_prebuilt (or any Gazelle binary with the buf extension compiled in)
- Enable
buf as a language but not proto:
aspect_gazelle(
name = "gazelle",
languages = [
"buf",
"python",
"starlark",
],
)
- Have a
buf.yaml in the repo
- 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
Description
The buf Gazelle extension crashes with a nil pointer dereference when the
protoGazelle language is not also enabled. This happens becauseloadConfigingazelle/buf/config.go:117callsproto.GetProtoConfig(gazelleConfig)without checking for nil.Steps to Reproduce
aspect_gazelle_prebuilt(or any Gazelle binary with the buf extension compiled in)bufas a language but notproto:buf.yamlin the repobazelisk run gazelleExpected Behavior
Gazelle should either:
bufrequiresprototo also be enabledActual Behavior
Root Cause
In
gazelle/buf/config.goline 117:proto.GetProtoConfig(gazelleConfig)returns nil when the proto Gazelle language isn't registered, and the subsequent field access panics.Environment