Skip to content

prometheus.InvalidDesc.String() is formatted incorrectly #1684

Closed
@SealOfTime

Description

@SealOfTime

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

type Desc struct {
	//...
	variableLabels *compiledLabels
        //...
}

func NewInvalidDesc(err error) *Desc {
	return &Desc{
		err: err,
	}
}

func (d *Desc) String() string {
	//...
	vlStrings := make([]string, 0, len(d.variableLabels.names))
	for _, vl := range d.variableLabels.names {
        //...
}

NewInvalidDesc will create a Desc with variableLabels equal to nil, therefore accessing its field names 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions