From 54c647f8b4c2567902f9112c387f7464b246b54b Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 31 Mar 2025 11:28:18 +0200 Subject: [PATCH] Sanitize darwin thermal strings Use `utils.SafeBytesToString()` to sanitize C strings the Darwin thermal collector. Signed-off-by: Ben Kochie --- collector/thermal_darwin.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/collector/thermal_darwin.go b/collector/thermal_darwin.go index 0a3b8981f4..9a74fdbdd8 100644 --- a/collector/thermal_darwin.go +++ b/collector/thermal_darwin.go @@ -50,6 +50,8 @@ import ( "log/slog" "unsafe" + "github.com/prometheus/node_exporter/collector/utils" + "github.com/prometheus/client_golang/prometheus" ) @@ -176,7 +178,7 @@ func mappingCFStringToString(s C.CFStringRef) string { buf := make([]byte, maxBufLen) var usedBufLen C.CFIndex _ = C.CFStringGetBytes(s, C.CFRange{0, length}, C.kCFStringEncodingUTF8, C.UInt8(0), C.false, (*C.UInt8)(&buf[0]), maxBufLen, &usedBufLen) - return string(buf[:usedBufLen]) + return utils.SafeBytesToString(buf[:usedBufLen]) } func mappingCFNumberLongToInt(n C.CFNumberRef) int {