Explorar o código

Improving validation of port numbers in scripting and .NET assembly

(cherry picked from commit 7bea1ac8b1f0e53611667dc429830a9669541946)

Source commit: 59dff692eccbe30b2d87f8aa242a04666554f29d
Martin Prikryl %!s(int64=4) %!d(string=hai) anos
pai
achega
1af27ad66a
Modificáronse 2 ficheiros con 8 adicións e 4 borrados
  1. 2 2
      dotnet/SessionOptions.cs
  2. 6 2
      source/core/SessionData.cpp

+ 2 - 2
dotnet/SessionOptions.cs

@@ -401,9 +401,9 @@ namespace WinSCP
 
         private void SetPortNumber(int value)
         {
-            if (value < 0)
+            if ((value < 1) || (value > 65535))
             {
-                throw new ArgumentException("Port number cannot be negative");
+                throw new ArgumentException("Port number has to be in range from 0 to 65535");
             }
 
             _portNumber = value;

+ 6 - 2
source/core/SessionData.cpp

@@ -2107,8 +2107,12 @@ bool __fastcall TSessionData::ParseUrl(UnicodeString Url, TOptions * Options,
       // expanded from ?: operator, as it caused strange "access violation" errors
       if (!HostInfo.IsEmpty())
       {
-        PortNumber = StrToIntDef(DecodeUrlChars(HostInfo), -1);
-        PortNumberDefined = true;
+        int APortNumber = StrToIntDef(DecodeUrlChars(HostInfo), -1);
+        if ((APortNumber > 0) && (APortNumber <= 65535))
+        {
+          PortNumber = APortNumber;
+          PortNumberDefined = true;
+        }
       }
       else if (ProtocolDefined)
       {