-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
prometheus.InvalidDesc.String() is formatted incorrectly #1684
Comments
Hey there, @SealOfTime! I'm here to assist you with any bugs, questions, or contributions while we wait for a human maintainer. Let's squash those bugs together! 🤖 To prevent a nil pointer dereference in the func (d *Desc) String() string {
lpStrings := make([]string, 0, len(d.constLabelPairs))
for _, lp := range d.constLabelPairs {
lpStrings = append(
lpStrings,
fmt.Sprintf("%s=%q", lp.GetName(), lp.GetValue()),
)
}
vlStrings := []string{}
if d.variableLabels != nil {
vlStrings = make([]string, 0, len(d.variableLabels.names))
for _, vl := range d.variableLabels.names {
if fn, ok := d.variableLabels.labelConstraints[vl]; ok && fn != nil {
vlStrings = append(vlStrings, fmt.Sprintf("c(%s)", vl))
} else {
vlStrings = append(vlStrings, vl)
}
}
}
return fmt.Sprintf(
"Desc{fqName: %q, help: %q, constLabels: {%s}, variableLabels: {%s}}",
d.fqName,
d.help,
strings.Join(lpStrings, ","),
strings.Join(vlStrings, ","),
)
} This modification ensures that the code checks if |
…for nil label values Fixes #1684 Signed-off-by: Kemal Akkoyun <[email protected]>
…for nil label values Fixes #1684 Signed-off-by: Kemal Akkoyun <[email protected]>
…for nil label values (#1687) Fixes #1684 Signed-off-by: Kemal Akkoyun <[email protected]>
…for nil label values (prometheus#1687) Fixes prometheus#1684 Signed-off-by: Kemal Akkoyun <[email protected]> Signed-off-by: Eugene <[email protected]>
On v1.20.5, if String() method of a prometheus.Desc returned from NewInvalidDesc called, it will cause a nil pointer derefence, which will result in an incorrectly formatted string
NewInvalidDesc will create a Desc with
variableLabels
equal to nil, therefore accessing its fieldnames
will cause a nil-pointer dereference.The result is:
descriptor %!s(PANIC=String method: runtime error: invalid memory address or nil pointer dereference) is invalid: test
The consequence of that is an unpleasant error message in prometheus.Register
The text was updated successfully, but these errors were encountered: