Skip to content

Commit 42c80e0

Browse files
committed
fix(event): Registry data buffer bound checks
In some occasions, the registry data buffer is provided without enough length to satisfy the underlying value type. To prevent panics, when converting the buffer to an integer data type, incorporate bound checks.
1 parent 486a7cf commit 42c80e0

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

pkg/event/param_windows.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,40 @@ func (e *Event) produceParams(evt *etw.EventRecord) {
540540
case registry.BINARY:
541541
e.AppendParam(params.RegData, params.Binary, b)
542542
case registry.DWORD:
543-
e.AppendParam(params.RegData, params.Uint32, binary.LittleEndian.Uint32(b))
543+
var v uint32
544+
switch len(b) {
545+
case 4:
546+
v = binary.LittleEndian.Uint32(b)
547+
case 2:
548+
v = uint32(binary.LittleEndian.Uint16(b))
549+
case 1:
550+
v = uint32(b[0])
551+
}
552+
e.AppendParam(params.RegData, params.Uint32, v)
544553
case registry.DWORD_BIG_ENDIAN:
545-
e.AppendParam(params.RegData, params.Uint32, binary.BigEndian.Uint32(b))
554+
var v uint32
555+
switch len(b) {
556+
case 4:
557+
v = binary.BigEndian.Uint32(b)
558+
case 2:
559+
v = uint32(binary.BigEndian.Uint16(b))
560+
case 1:
561+
v = uint32(b[0])
562+
}
563+
e.AppendParam(params.RegData, params.Uint32, v)
546564
case registry.QWORD:
547-
e.AppendParam(params.RegData, params.Uint64, binary.LittleEndian.Uint64(b))
565+
var v uint64
566+
switch len(b) {
567+
case 8:
568+
v = binary.LittleEndian.Uint64(b)
569+
case 4:
570+
v = uint64(binary.LittleEndian.Uint32(b))
571+
case 2:
572+
v = uint64(binary.LittleEndian.Uint16(b))
573+
case 1:
574+
v = uint64(b[0])
575+
}
576+
e.AppendParam(params.RegData, params.Uint64, v)
548577
}
549578
}
550579
case CreateFile:

0 commit comments

Comments
 (0)