Skip to content

Commit ce9d22d

Browse files
BornToBeRootclaude
andcommitted
Fix: Ping buffer from the settings file is limited
IP Scanner, Port Scanner, Ping Monitor and Traceroute created the ping buffer from the setting without a limit: a value edited in the settings file threw (negative) or made every ping fail (more than 65500 bytes). Limited to the input range (1 - 65500) when the buffer is created, with one constant for the maximum (also used by the settings upgrade). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 08a2466 commit ce9d22d

6 files changed

Lines changed: 24 additions & 15 deletions

File tree

‎Source/NETworkManager.Settings/GlobalStaticConfiguration.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public static class GlobalStaticConfiguration
4343
// known constant) that are expected to be "close enough" rather than bit-for-bit equal.
4444
public static double FloatPointFix => 1.0;
4545

46+
// ICMP config: maximum buffer of a ping (.NET's Ping throws for more than 65500 bytes)
47+
public static int ICMPBufferMaximum => 65500;
48+
4649
// Profile config
4750
public static bool Profile_TagsMatchAny => true;
4851
public static bool Profile_ExpandProfileView => true;

‎Source/NETworkManager.Settings/SettingsManager.cs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -865,22 +865,22 @@ private static void UpgradeToLatest(Version version)
865865
}
866866

867867
// ICMP buffer - .NET's Ping throws for more than 65500 bytes, the settings allowed up to 65535
868-
if (Current.IPScanner_ICMPBuffer > 65500)
868+
if (Current.IPScanner_ICMPBuffer > GlobalStaticConfiguration.ICMPBufferMaximum)
869869
{
870-
Log.Info($"Update \"IPScanner_ICMPBuffer\" from {Current.IPScanner_ICMPBuffer} to 65500...");
871-
Current.IPScanner_ICMPBuffer = 65500;
870+
Log.Info($"Update \"IPScanner_ICMPBuffer\" from {Current.IPScanner_ICMPBuffer} to {GlobalStaticConfiguration.ICMPBufferMaximum}...");
871+
Current.IPScanner_ICMPBuffer = GlobalStaticConfiguration.ICMPBufferMaximum;
872872
}
873873

874-
if (Current.PingMonitor_Buffer > 65500)
874+
if (Current.PingMonitor_Buffer > GlobalStaticConfiguration.ICMPBufferMaximum)
875875
{
876-
Log.Info($"Update \"PingMonitor_Buffer\" from {Current.PingMonitor_Buffer} to 65500...");
877-
Current.PingMonitor_Buffer = 65500;
876+
Log.Info($"Update \"PingMonitor_Buffer\" from {Current.PingMonitor_Buffer} to {GlobalStaticConfiguration.ICMPBufferMaximum}...");
877+
Current.PingMonitor_Buffer = GlobalStaticConfiguration.ICMPBufferMaximum;
878878
}
879879

880-
if (Current.Traceroute_Buffer > 65500)
880+
if (Current.Traceroute_Buffer > GlobalStaticConfiguration.ICMPBufferMaximum)
881881
{
882-
Log.Info($"Update \"Traceroute_Buffer\" from {Current.Traceroute_Buffer} to 65500...");
883-
Current.Traceroute_Buffer = 65500;
882+
Log.Info($"Update \"Traceroute_Buffer\" from {Current.Traceroute_Buffer} to {GlobalStaticConfiguration.ICMPBufferMaximum}...");
883+
Current.Traceroute_Buffer = GlobalStaticConfiguration.ICMPBufferMaximum;
884884
}
885885

886886
// Add new Port Scanner port profiles

‎Source/NETworkManager/ViewModels/IPScannerViewModel.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,9 @@ private static IPScannerOptions CreateScanOptions(int[] ports)
901901
MaxPortThreads = SettingsManager.Current.IPScanner_MaxPortThreads,
902902
ICMPAttempts = SettingsManager.Current.IPScanner_ICMPAttempts,
903903
ICMPTimeout = SettingsManager.Current.IPScanner_ICMPTimeout,
904-
ICMPBuffer = new byte[SettingsManager.Current.IPScanner_ICMPBuffer],
904+
// Limits of the input (a value edited in the settings file would throw or make every ping fail)
905+
ICMPBuffer = new byte[Math.Clamp(SettingsManager.Current.IPScanner_ICMPBuffer, 1,
906+
GlobalStaticConfiguration.ICMPBufferMaximum)],
905907
ResolveHostname = SettingsManager.Current.IPScanner_ResolveHostname,
906908
PortScanEnabled = SettingsManager.Current.IPScanner_PortScanEnabled,
907909
PortScanPorts = ports,

‎Source/NETworkManager/ViewModels/PingMonitorViewModel.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,9 @@ public void Start()
571571
var ping = new Ping
572572
{
573573
Timeout = SettingsManager.Current.PingMonitor_Timeout,
574-
Buffer = new byte[SettingsManager.Current.PingMonitor_Buffer],
574+
// Limits of the input (a value edited in the settings file would throw or make every ping fail)
575+
Buffer = new byte[Math.Clamp(SettingsManager.Current.PingMonitor_Buffer, 1,
576+
GlobalStaticConfiguration.ICMPBufferMaximum)],
575577
TTL = SettingsManager.Current.PingMonitor_TTL,
576578
DontFragment = SettingsManager.Current.PingMonitor_DontFragment,
577579
WaitTime = SettingsManager.Current.PingMonitor_WaitTime

‎Source/NETworkManager/ViewModels/PortScannerViewModel.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,9 +1286,9 @@ private static PortScannerOptions CreateScanOptions()
12861286
PingHostsBeforeScan = SettingsManager.Current.PortScanner_PingHostsBeforeScan,
12871287
ICMPAttempts = SettingsManager.Current.PortScanner_ICMPAttempts,
12881288
ICMPTimeout = SettingsManager.Current.PortScanner_ICMPTimeout,
1289-
// Limits of the input - a value edited in the settings file would throw (negative) or make every ping fail
1290-
// (.NET's Ping throws for more than 65500 bytes)
1291-
ICMPBuffer = new byte[Math.Clamp(SettingsManager.Current.PortScanner_ICMPBuffer, 1, 65500)],
1289+
// Limits of the input (a value edited in the settings file would throw or make every ping fail)
1290+
ICMPBuffer = new byte[Math.Clamp(SettingsManager.Current.PortScanner_ICMPBuffer, 1,
1291+
GlobalStaticConfiguration.ICMPBufferMaximum)],
12921292
ResolveHostname = SettingsManager.Current.PortScanner_ResolveHostname,
12931293
ShowAllResults = SettingsManager.Current.PortScanner_ShowAllResults
12941294
};

‎Source/NETworkManager/ViewModels/TracerouteViewModel.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ await DNSClientHelper.ResolveAorAaaaAsync(Host,
420420
{
421421
var traceroute = new Traceroute(new TracerouteOptions(
422422
SettingsManager.Current.Traceroute_Timeout,
423-
new byte[SettingsManager.Current.Traceroute_Buffer],
423+
// Limits of the input (a value edited in the settings file would throw or make every ping fail)
424+
new byte[Math.Clamp(SettingsManager.Current.Traceroute_Buffer, 1,
425+
GlobalStaticConfiguration.ICMPBufferMaximum)],
424426
SettingsManager.Current.Traceroute_MaximumHops,
425427
true,
426428
SettingsManager.Current.Traceroute_ResolveHostname,

0 commit comments

Comments
 (0)