Skip to content

Commit 3d1d052

Browse files
authored
Remove the use of BinaryFormatter in PSRP serialization (PowerShell#17133)
1 parent 65d8f11 commit 3d1d052

File tree

5 files changed

+3
-99
lines changed

5 files changed

+3
-99
lines changed

src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,8 +1601,6 @@ internal static RemoteDataObject GenerateClientSessionCapability(RemoteSessionCa
16011601
Guid runspacePoolId)
16021602
{
16031603
PSObject temp = GenerateSessionCapability(capability);
1604-
temp.Properties.Add(
1605-
new PSNoteProperty(RemoteDataNameStrings.TimeZone, RemoteSessionCapability.GetCurrentTimeZoneInByteFormat()));
16061604
return RemoteDataObject.CreateFrom(capability.RemotingDestination,
16071605
RemotingDataType.SessionCapability, runspacePoolId, Guid.Empty, temp);
16081606
}
@@ -2373,24 +2371,6 @@ internal static RemoteSessionCapability GetSessionCapability(object data)
23732371
RemotingDestination.InvalidDestination,
23742372
protocolVersion, psVersion, serializationVersion);
23752373

2376-
if (dataAsPSObject.Properties[RemoteDataNameStrings.TimeZone] != null)
2377-
{
2378-
// Binary deserialization of timezone info via BinaryFormatter is unsafe,
2379-
// so don't deserialize any untrusted client data using this API.
2380-
//
2381-
// In addition, the binary data being sent by the client doesn't represent
2382-
// the client's current TimeZone unless they somehow accessed the
2383-
// StandardName and DaylightName. These properties are initialized lazily
2384-
// by the .NET Framework, and would be populated by the server with local
2385-
// values anyways.
2386-
//
2387-
// So just return the CurrentTimeZone.
2388-
2389-
#if !CORECLR // TimeZone Not In CoreCLR
2390-
result.TimeZone = TimeZone.CurrentTimeZone;
2391-
#endif
2392-
}
2393-
23942374
return result;
23952375
}
23962376

src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteSessionCapability.cs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.IO;
66
using System.Management.Automation.Host;
77
using System.Management.Automation.Internal.Host;
8-
using System.Runtime.Serialization.Formatters.Binary;
98

109
using Dbg = System.Management.Automation.Diagnostics;
1110

@@ -25,8 +24,6 @@ internal class RemoteSessionCapability
2524
private readonly Version _serversion;
2625
private Version _protocolVersion;
2726
private readonly RemotingDestination _remotingDestination;
28-
private static byte[] _timeZoneInByteFormat;
29-
private TimeZoneInfo _timeZone;
3027

3128
#endregion
3229

@@ -91,64 +88,6 @@ internal static RemoteSessionCapability CreateServerCapability()
9188
{
9289
return new RemoteSessionCapability(RemotingDestination.Client);
9390
}
94-
95-
/// <summary>
96-
/// This is static property which gets Current TimeZone in byte format
97-
/// by using ByteFormatter.
98-
/// This is static to make client generate this only once.
99-
/// </summary>
100-
internal static byte[] GetCurrentTimeZoneInByteFormat()
101-
{
102-
if (_timeZoneInByteFormat == null)
103-
{
104-
Exception e = null;
105-
try
106-
{
107-
BinaryFormatter formatter = new BinaryFormatter();
108-
using (MemoryStream stream = new MemoryStream())
109-
{
110-
#pragma warning disable SYSLIB0011
111-
formatter.Serialize(stream, TimeZoneInfo.Local);
112-
#pragma warning restore SYSLIB0011
113-
stream.Seek(0, SeekOrigin.Begin);
114-
byte[] result = new byte[stream.Length];
115-
stream.Read(result, 0, (int)stream.Length);
116-
_timeZoneInByteFormat = result;
117-
}
118-
}
119-
catch (ArgumentNullException ane)
120-
{
121-
e = ane;
122-
}
123-
catch (System.Runtime.Serialization.SerializationException sre)
124-
{
125-
e = sre;
126-
}
127-
catch (System.Security.SecurityException se)
128-
{
129-
e = se;
130-
}
131-
132-
// if there is any exception serializing the timezone information
133-
// ignore it and dont try to serialize again.
134-
if (e != null)
135-
{
136-
_timeZoneInByteFormat = Array.Empty<byte>();
137-
}
138-
}
139-
140-
return _timeZoneInByteFormat;
141-
}
142-
143-
/// <summary>
144-
/// Gets the TimeZone of the destination machine. This may be null.
145-
/// </summary>
146-
internal TimeZoneInfo TimeZone
147-
{
148-
get { return _timeZone; }
149-
150-
set { _timeZone = value; }
151-
}
15291
}
15392

15493
/// <summary>

src/System.Management.Automation/engine/remoting/fanin/PSPrincipal.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ namespace System.Management.Automation.Remoting
1818
/// <summary>
1919
/// This class is used in the server side remoting scenarios. This class
2020
/// holds information about the incoming connection like:
21-
/// (a) Client's TimeZone
22-
/// (b) Connecting User information
23-
/// (c) Connection String used by the user to connect to the server.
21+
/// (a) Connecting User information
22+
/// (b) Connection String used by the user to connect to the server.
2423
/// </summary>
2524
[Serializable]
2625
public sealed class PSSenderInfo : ISerializable
@@ -81,8 +80,6 @@ private PSSenderInfo(SerializationInfo info, StreamingContext context)
8180
UserInfo = senderInfo.UserInfo;
8281
ConnectionString = senderInfo.ConnectionString;
8382
_applicationArguments = senderInfo._applicationArguments;
84-
85-
ClientTimeZone = senderInfo.ClientTimeZone;
8683
}
8784
catch (Exception)
8885
{
@@ -129,11 +126,7 @@ public PSPrincipal UserInfo
129126
/// <summary>
130127
/// Contains the TimeZone information from the client machine.
131128
/// </summary>
132-
public TimeZoneInfo ClientTimeZone
133-
{
134-
get;
135-
internal set;
136-
}
129+
public TimeZoneInfo ClientTimeZone => null;
137130

138131
/// <summary>
139132
/// Connection string used by the client to connect to the server. This is

src/System.Management.Automation/engine/remoting/server/serverremotesession.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -749,13 +749,6 @@ private void HandleCreateRunspacePool(object sender, RemoteDataEventArgs createR
749749
RemoteDataObject<PSObject> rcvdData = createRunspaceEventArg.ReceivedData;
750750
Dbg.Assert(rcvdData != null, "rcvdData must be non-null");
751751

752-
// set the PSSenderInfo sent in the first packets
753-
// This is used by the initial session state configuration providers like Exchange.
754-
if (Context != null)
755-
{
756-
_senderInfo.ClientTimeZone = Context.ClientCapability.TimeZone;
757-
}
758-
759752
_senderInfo.ApplicationArguments = RemotingDecoder.GetApplicationArguments(rcvdData.Data);
760753

761754
// Get Initial Session State from custom session config suppliers

src/System.Management.Automation/engine/serialization.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7212,7 +7212,6 @@ internal static PSSenderInfo RehydratePSSenderInfo(PSObject pso)
72127212

72137213
PSSenderInfo senderInfo = new PSSenderInfo(psPrincipal, GetPropertyValue<string>(pso, "ConnectionString"));
72147214

7215-
senderInfo.ClientTimeZone = TimeZoneInfo.Local;
72167215
senderInfo.ApplicationArguments = GetPropertyValue<PSPrimitiveDictionary>(pso, "ApplicationArguments");
72177216

72187217
return senderInfo;

0 commit comments

Comments
 (0)