From e5caa394c8edf8d1da11627da0d5af36a49627c6 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 31 Mar 2025 12:46:39 +0200 Subject: [PATCH] Sanitize darwin thermal strings (#3294) 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 0a3b8981..9a74fdbd 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 {