Skip to content

Commit e5caa39

Browse files
authored
Sanitize darwin thermal strings (#3294)
Use `utils.SafeBytesToString()` to sanitize C strings the Darwin thermal collector. Signed-off-by: Ben Kochie <[email protected]>
1 parent 8c3f1a2 commit e5caa39

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

collector/thermal_darwin.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import (
5050
"log/slog"
5151
"unsafe"
5252

53+
"github.com/prometheus/node_exporter/collector/utils"
54+
5355
"github.com/prometheus/client_golang/prometheus"
5456
)
5557

@@ -176,7 +178,7 @@ func mappingCFStringToString(s C.CFStringRef) string {
176178
buf := make([]byte, maxBufLen)
177179
var usedBufLen C.CFIndex
178180
_ = C.CFStringGetBytes(s, C.CFRange{0, length}, C.kCFStringEncodingUTF8, C.UInt8(0), C.false, (*C.UInt8)(&buf[0]), maxBufLen, &usedBufLen)
179-
return string(buf[:usedBufLen])
181+
return utils.SafeBytesToString(buf[:usedBufLen])
180182
}
181183

182184
func mappingCFNumberLongToInt(n C.CFNumberRef) int {

0 commit comments

Comments
 (0)