Skip to content

Commit

Permalink
[Windows] Add max partitions
Browse files Browse the repository at this point in the history
It would be bad if we allowed unreasonable amounts of partitions
  • Loading branch information
Sploder12 committed Jan 30, 2025
1 parent f77492b commit 06db5bc
Show file tree
Hide file tree
Showing 3 changed files with 494 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/collector/sysinfo/sysinfo_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ func (s Manager) collectBlocks() (blks []diskInfo, err error) {
return nil, err
}

const maxPartitions = 128

blks = make([]diskInfo, 0, len(disks))
for _, d := range disks {
parts, err := strconv.Atoi(d["Partitions"])
Expand All @@ -224,6 +226,10 @@ func (s Manager) collectBlocks() (blks []diskInfo, err error) {
s.opts.log.Warn("disk partitions was negative", "value", parts)
parts = 0
}
if parts > maxPartitions {
s.opts.log.Warn("disk partitions too large", "value", parts)
parts = maxPartitions
}

c := diskInfo{
Name: d["Name"],
Expand Down
62 changes: 62 additions & 0 deletions internal/collector/sysinfo/sysinfo_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,20 @@ func TestCollectWindows(t *testing.T) {
},
},

"Malicious disk information": {
productInfo: "regular",
cpuInfo: "regular",
gpuInfo: "regular",
memoryInfo: "regular",
diskInfo: "malicious",
partitionInfo: "regular",
screenInfo: "regular",

logs: map[slog.Level]uint{
slog.LevelWarn: 3,
},
},

"Missing partition information": {
productInfo: "regular",
cpuInfo: "regular",
Expand Down Expand Up @@ -772,6 +786,53 @@ SCSIPort : 1
SCSITargetId : 0
SerialNumber : DEAD_BEEF_D34D_B33F_DEAD_B33F_D34D_BEEF.
Signature :`)
case "malicious":
fmt.Println(`
Partitions : 999999999999
BytesPerSector : 512
Index : 0
SectorsPerTrack : 63
Size : 2000396321280
TotalCylinders : 243201
TotalHeads : 255
TotalSectors : 3907024065
TotalTracks : 62016255
TracksPerCylinder : 255
Caption : WD Green SN350 2TB
Description : Disk drive
Name : \\.\PHYSICALDRIVE0
Model : WD Green SN350 2TB
Partitions : -1
BytesPerSector : 512
Index : 1
SectorsPerTrack : 63
Size : 2000396321280
TotalCylinders : 243201
TotalHeads : 255
TotalSectors : 3907024065
TotalTracks : 62016255
TracksPerCylinder : 255
Caption : WD Green SN350 2TB
Description : Disk drive
Name : \\.\PHYSICALDRIVE0
Model : WD Green SN350 2TB
Partitions : one gazillion
BytesPerSector : 512
Index : 2
SectorsPerTrack : 63
Size : 2000396321280
TotalCylinders : 243201
TotalHeads : 255
TotalSectors : 3907024065
TotalTracks : 62016255
TracksPerCylinder : 255
Caption : WD Green SN350 2TB
Description : Disk drive
Name : \\.\PHYSICALDRIVE0
Model : WD Green SN350 2TB`)
case "":
fallthrough
case "missing":
Expand Down Expand Up @@ -937,6 +998,7 @@ Type : GPT: Basic Data`)
Index : -1
Name : Disk #0, Partition #-1
DiskIndex : 0
Size : 314572800
Index : alpha
Expand Down
Loading

0 comments on commit 06db5bc

Please sign in to comment.