Skip to content

config: fix TLSVersion.String() printing pointer address#929

Merged
roidelapluie merged 1 commit into
prometheus:mainfrom
s3onghyun:fix-tlsversion-stringer
Jun 24, 2026
Merged

config: fix TLSVersion.String() printing pointer address#929
roidelapluie merged 1 commit into
prometheus:mainfrom
s3onghyun:fix-tlsversion-stringer

Conversation

@s3onghyun

Copy link
Copy Markdown
Contributor

What

TLSVersion.String() falls back to fmt.Sprintf("%d", tv) for a version not present in the TLSVersions map — but tv is the *TLSVersion pointer, so it prints the pointer's memory address as a decimal integer instead of the numeric TLS version.

func (tv *TLSVersion) String() string {
	if tv == nil || *tv == 0 {
		return ""
	}
	for s, v := range TLSVersions {
		if *tv == v {
			return s
		}
	}
	return fmt.Sprintf("%d", tv) // <- prints &tv address, not *tv
}

The sibling methods MarshalYAML and MarshalJSON already dereference correctly; String() was the lone outlier, and the existing test only covered the known-value path so it was never caught (go vet doesn't flag it either).

Fix

Dereference the pointer: tv*tv.

Test

Added TestTLSVersionStringerUnknown. Before the fix it printed a pointer address (e.g. "75679541043424"); after, it correctly returns "39321". go test ./config/ is green.

The fallback branch passed the *TLSVersion pointer to fmt.Sprintf("%d"),
so an unknown TLS version (one not in the TLSVersions map) rendered as the
pointer's memory address instead of the numeric version. Dereference the
pointer like the MarshalYAML/MarshalJSON methods already do.

Signed-off-by: Seonghyun Hong <s3onghyun.hong@gmail.com>
@roidelapluie roidelapluie merged commit 6d120ca into prometheus:main Jun 24, 2026
8 checks passed
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