Sanitize darwin thermal strings (#3294)

Use `utils.SafeBytesToString()` to sanitize C strings the Darwin
thermal collector.

Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
Ben Kochie 2025-03-31 12:46:39 +02:00 committed by GitHub
parent 8c3f1a2da3
commit e5caa394c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,6 +50,8 @@ import (
"log/slog" "log/slog"
"unsafe" "unsafe"
"github.com/prometheus/node_exporter/collector/utils"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
@ -176,7 +178,7 @@ func mappingCFStringToString(s C.CFStringRef) string {
buf := make([]byte, maxBufLen) buf := make([]byte, maxBufLen)
var usedBufLen C.CFIndex var usedBufLen C.CFIndex
_ = C.CFStringGetBytes(s, C.CFRange{0, length}, C.kCFStringEncodingUTF8, C.UInt8(0), C.false, (*C.UInt8)(&buf[0]), maxBufLen, &usedBufLen) _ = 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 { func mappingCFNumberLongToInt(n C.CFNumberRef) int {