[Xymon] Bug Report - Powershell client - overflow with disk size for large disks

Ribeiro, Glauber glauber.ribeiro at experian.com
Fri Sep 5 18:30:37 CEST 2014


Shout-out to David Baldwin:

Xymonclient.ps1, lines 346-347:

[uint32]$diskusedKB = ([uint32]($d.Size/1KB)) - ([uint32]($d.FreeSpace/1KB))      # PS ver 1 doesnt support subtraction uint64's
[uint32]$disksizeKB = [uint32]($d.size/1KB)

Which is fine, until you have a disk that is large enough. When that happens, there is truncation. In the example below:
 
1K-blocks is correct
Used is wrong - should be 2220117608 instead of 68526964
Avail is correct
Capacity is wrong - should be 4% instead of 27%
Summary is correct


Example:

[disk]
Filesystem      1K-blocks      Used     Avail  Capacity    Mounted Summary(Total\Avail GB)
...
F               2306837260  68526964  87800516       27%   /FIXED/F 2199.97\83.73


I'm actually having some trouble figuring out where the overflow happens. I think Powershell must be using signed integers in some of the calculations. Maybe it's because of the 1KB constant.

PS> 1KB | get-member

   TypeName: System.Int32


My fix was simply to remove all the [uint32] casts on those 2 lines. I'm running PS v2

PS> $PSVersionTable

Name                           Value
----                           -----
CLRVersion                     2.0.50727.5466
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1


If there is a pressing need to keep v1 compatibility, there may be a way to refactor the math so it works with uint32 (maybe casting the 1KBs), but I have a feeling that v2 compatibility is good enough.

Thanks,


glauber


(Let me know if you'd like me to investigate further.)
---
Glauber Ribeiro
Experian Automotive, Schaumburg IL
Infrastructure and Information Security



More information about the Xymon mailing list