Imported Upstream version 5.10.0.69

Former-commit-id: fc39669a0b707dd3c063977486506b6793da2890
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-29 19:03:06 +00:00
parent d8f8abd549
commit e2950ec768
6283 changed files with 453847 additions and 91879 deletions

View File

@@ -197,8 +197,6 @@
<Reference Include="Microsoft.Win32.Primitives" />
<Reference Include="System.Collections" />
<Reference Include="System.Collections.NonGeneric" />
<Reference Include="System.Runtime.CompilerServices.Unsafe" />
<Reference Include="System.Diagnostics.Contracts" />
<Reference Include="System.Diagnostics.Debug" />
<Reference Include="System.Diagnostics.Tracing" />
<Reference Include="System.Resources.ResourceManager" />

View File

@@ -68,30 +68,30 @@ namespace System.Net
private string m_domainKey = string.Empty; // Do not rename (binary serialization)
/*
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
public, this is a temporary workaround till that happens.
*/
#if uap
#if uap
public
#else
#else
internal
#endif
bool IsQuotedVersion = false;
/*
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
public, this is a temporary workaround till that happens.
*/
#if uap
#if uap
public
#else
#else
internal
#endif
bool IsQuotedDomain = false;
@@ -243,16 +243,16 @@ namespace System.Net
}
}
/*
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
public, this is a temporary workaround till that happens.
*/
#if uap
#if uap
public
#else
#else
internal
#endif
bool InternalSetName(string value)
@@ -287,16 +287,16 @@ namespace System.Net
}
}
/*
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
public, this is a temporary workaround till that happens.
*/
#if uap
#if uap
public
#else
#else
internal
#endif
Cookie Clone()
@@ -325,8 +325,8 @@ namespace System.Net
clonedCookie.Version = m_version;
clonedCookie.Secure = m_secure;
// The variant is set when we set properties like port/version. So,
// we should copy over the variant from the original cookie after
// The variant is set when we set properties like port/version. So,
// we should copy over the variant from the original cookie after
// we set all other properties
clonedCookie.m_cookieVariant = m_cookieVariant;
@@ -704,16 +704,16 @@ namespace System.Net
}
}
/*
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
public, this is a temporary workaround till that happens.
*/
#if uap
#if uap
public
#else
#else
internal
#endif
CookieVariant Variant
@@ -845,16 +845,16 @@ namespace System.Net
}
}
/*
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
public, this is a temporary workaround till that happens.
*/
#if uap
#if uap
public
#else
#else
internal
#endif
string ToServerString()
@@ -902,32 +902,5 @@ namespace System.Net
}
return result == EqualsLiteral ? null : result;
}
#if DEBUG
internal void Dump()
{
if (NetEventSource.IsEnabled)
{
if (NetEventSource.IsEnabled) NetEventSource.Info(this,
"Cookie: " + ToString() + "->\n"
+ "\tComment = " + Comment + "\n"
+ "\tCommentUri = " + CommentUri + "\n"
+ "\tDiscard = " + Discard + "\n"
+ "\tDomain = " + Domain + "\n"
+ "\tExpired = " + Expired + "\n"
+ "\tExpires = " + Expires + "\n"
+ "\tName = " + Name + "\n"
+ "\tPath = " + Path + "\n"
+ "\tPort = " + Port + "\n"
+ "\tSecure = " + Secure + "\n"
+ "\tTimeStamp = " + TimeStamp + "\n"
+ "\tValue = " + Value + "\n"
+ "\tVariant = " + Variant + "\n"
+ "\tVersion = " + Version + "\n"
+ "\tHttpOnly = " + HttpOnly + "\n"
);
}
}
#endif
}
}

View File

@@ -175,16 +175,16 @@ namespace System.Net
// If isStrict == true, replace the cookie if found same with newest Variant.
// Returns 1 if added, 0 if replaced or rejected.
/*
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
public, this is a temporary workaround till that happens.
*/
#if uap
#if uap
public
#else
#else
internal
#endif
int InternalAdd(Cookie cookie, bool isStrict)
@@ -247,19 +247,5 @@ namespace System.Net
{
return m_list.GetEnumerator();
}
#if DEBUG
internal void Dump()
{
if (NetEventSource.IsEnabled)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this);
foreach (Cookie cookie in this)
{
cookie.Dump();
}
}
}
#endif
}
}

View File

@@ -56,7 +56,7 @@ using System.Text;
namespace System.Net
{
internal struct HeaderVariantInfo
internal readonly struct HeaderVariantInfo
{
private readonly string _name;
private readonly CookieVariant _variant;
@@ -677,7 +677,11 @@ namespace System.Net
if (cookie == null)
{
break;
if (parser.EndofHeader())
{
break;
}
continue;
}
// Parser marks invalid cookies this way
@@ -810,8 +814,6 @@ namespace System.Net
{
for (int i = 0; i < domainAttribute.Count; i++)
{
bool found = false;
bool defaultAdded = false;
PathList pathList;
lock (m_domainTable.SyncRoot)
{
@@ -831,32 +833,10 @@ namespace System.Net
string path = (string)e.Key;
if (uri.AbsolutePath.StartsWith(CookieParser.CheckQuoted(path)))
{
found = true;
CookieCollection cc = (CookieCollection)e.Value;
cc.TimeStamp(CookieCollection.Stamp.Set);
MergeUpdateCollections(ref cookies, cc, port, isSecure, matchOnlyPlainCookie);
if (path == "/")
{
defaultAdded = true;
}
}
else if (found)
{
break;
}
}
}
if (!defaultAdded)
{
CookieCollection cc = (CookieCollection)pathList["/"];
if (cc != null)
{
cc.TimeStamp(CookieCollection.Stamp.Set);
MergeUpdateCollections(ref cookies, cc, port, isSecure, matchOnlyPlainCookie);
}
}

View File

@@ -7,6 +7,9 @@ using System.Runtime.Serialization;
namespace System.Net
{
[Serializable]
#if !MONO
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public class CookieException : FormatException, ISerializable
{
public CookieException() : base()
@@ -24,7 +27,6 @@ namespace System.Net
protected CookieException(SerializationInfo serializationInfo, StreamingContext streamingContext)
: base(serializationInfo, streamingContext)
{
throw new PlatformNotSupportedException();
}
void ISerializable.GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)

View File

@@ -418,7 +418,7 @@ namespace System.Net
}
}
internal struct CredentialHostKey : IEquatable<CredentialHostKey>
internal readonly struct CredentialHostKey : IEquatable<CredentialHostKey>
{
public readonly string Host;
public readonly string AuthenticationType;

View File

@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Buffers.Binary;
using System.Diagnostics;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
@@ -399,36 +400,17 @@ namespace System.Net
public static long HostToNetworkOrder(long host)
{
#if BIGENDIAN
return host;
#else
ulong value = (ulong)host;
value = (value << 32) | (value >> 32);
value = (value & 0x0000FFFF0000FFFF) << 16 | (value & 0xFFFF0000FFFF0000) >> 16;
value = (value & 0x00FF00FF00FF00FF) << 8 | (value & 0xFF00FF00FF00FF00) >> 8;
return (long)value;
#endif
return BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(host) : host;
}
public static int HostToNetworkOrder(int host)
{
#if BIGENDIAN
return host;
#else
uint value = (uint)host;
value = (value << 16) | (value >> 16);
value = (value & 0x00FF00FF) << 8 | (value & 0xFF00FF00) >> 8;
return (int)value;
#endif
return BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(host) : host;
}
public static short HostToNetworkOrder(short host)
{
#if BIGENDIAN
return host;
#else
return unchecked((short)((((int)host & 0xFF) << 8) | (int)((host >> 8) & 0xFF)));
#endif
return BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(host) : host;
}
public static long NetworkToHostOrder(long network)
@@ -635,16 +617,17 @@ namespace System.Net
Debug.Assert(scopeWritten);
hashCode = Marvin.ComputeHash32(
ref addressAndScopeIdSpan[0],
addressAndScopeIdLength,
addressAndScopeIdSpan,
Marvin.DefaultSeed);
}
else
{
Span<uint> addressOrScopeIdSpan = stackalloc uint[1];
addressOrScopeIdSpan[0] = _addressOrScopeId;
// For IPv4 addresses, we use Marvin on the integer representation of the Address.
hashCode = Marvin.ComputeHash32(
ref Unsafe.As<uint, byte>(ref _addressOrScopeId),
sizeof(uint),
addressOrScopeIdSpan.AsBytes(),
Marvin.DefaultSeed);
}
@@ -652,14 +635,6 @@ namespace System.Net
return _hashCode;
}
// For security, we need to be able to take an IPAddress and make a copy that's immutable and not derived.
internal IPAddress Snapshot()
{
return IsIPv4 ?
new IPAddress(PrivateAddress) :
new IPAddress(_numbers, PrivateScopeId);
}
// IPv4 192.168.1.1 maps as ::FFFF:192.168.1.1
public IPAddress MapToIPv6()
{

View File

@@ -5,6 +5,7 @@
using System.Diagnostics;
using System.IO;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
namespace System.Net
@@ -53,7 +54,7 @@ namespace System.Net
return false;
}
fixed (char* formattedPtr = &formatted.DangerousGetPinnableReference())
fixed (char* formattedPtr = &MemoryMarshal.GetReference(formatted))
{
charsWritten = IPv4AddressToStringHelper(address, formattedPtr);
}
@@ -160,7 +161,7 @@ namespace System.Net
int end = ipSpan.Length;
long tmpAddr;
fixed (char* ipStringPtr = &ipSpan.DangerousGetPinnableReference())
fixed (char* ipStringPtr = &MemoryMarshal.GetReference(ipSpan))
{
tmpAddr = IPv4AddressHelper.ParseNonCanonical(ipStringPtr, 0, ref end, notImplicitFile: true);
}
@@ -192,7 +193,7 @@ namespace System.Net
int end = ipSpan.Length;
bool isValid = false;
fixed (char* ipStringPtr = &ipSpan.DangerousGetPinnableReference())
fixed (char* ipStringPtr = &MemoryMarshal.GetReference(ipSpan))
{
isValid = IPv6AddressHelper.IsValidStrict(ipStringPtr, 0, ref end);
}

View File

@@ -149,22 +149,12 @@ namespace System.Net
public override bool Equals(object comparand)
{
if (!(comparand is IPEndPoint))
{
return false;
}
return ((IPEndPoint)comparand)._address.Equals(_address) && ((IPEndPoint)comparand)._port == _port;
return comparand is IPEndPoint other && other._address.Equals(_address) && other._port == _port;
}
public override int GetHashCode()
{
return _address.GetHashCode() ^ _port;
}
// For security, we need to be able to take an IPEndPoint and make a copy that's immutable and not derived.
internal IPEndPoint Snapshot()
{
return new IPEndPoint(Address.Snapshot(), Port);
}
}
}

View File

@@ -9,6 +9,9 @@ namespace System.Net.Sockets
{
/// <summary>Provides socket exceptions to the application.</summary>
[Serializable]
#if !MONO
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public partial class SocketException : Win32Exception
{
/// <summary>The SocketError or Int32 specified when constructing the exception.</summary>
@@ -44,7 +47,7 @@ namespace System.Net.Sockets
protected SocketException(SerializationInfo serializationInfo, StreamingContext streamingContext)
: base(serializationInfo, streamingContext)
{
throw new PlatformNotSupportedException();
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"{NativeErrorCode}:{Message}");
}
public override int ErrorCode => base.NativeErrorCode;

View File

@@ -143,7 +143,9 @@ namespace System.Net.Primitives.Unit.Tests
}
}; // RFC 2965
yield return new object[] { u,
yield return new object[]
{
u,
"name98=value98; port=\"80, 90\", name99=value99",
new Cookie[]
{
@@ -152,7 +154,8 @@ namespace System.Net.Primitives.Unit.Tests
}
}; // RFC 2965 (no path)
yield return new object[] {
yield return new object[]
{
uSecure,
"name98=value98; name98=value98; comment=comment; comment=comment2; commentURL=http://url.com; commentURL=commentURL2; discard; discard; domain=.uri.com; domain=domain2; max-age=400; max-age=400; path=/; path=path; port=\"80, 90, 443\"; port=port2; path=path; expires=Wed, 09 Jun 2021 10:18:14 GMT; expires=expires2; secure; secure; httponly; httponly; Version=100; Version=100, name99=value99",
new Cookie[]
@@ -162,7 +165,8 @@ namespace System.Net.Primitives.Unit.Tests
}
}; // Double entries
yield return new object[] {
yield return new object[]
{
u,
"name98=value98; commentURL=invalidurl",
new Cookie[]
@@ -171,7 +175,8 @@ namespace System.Net.Primitives.Unit.Tests
}
}; // Ignore invalid comment url
yield return new object[] {
yield return new object[]
{
u6,
"name98=value98; unknown1; unknown2=unknown",
new Cookie[]
@@ -180,7 +185,8 @@ namespace System.Net.Primitives.Unit.Tests
}
}; // Ignore unknown tokens
yield return new object[] {
yield return new object[]
{
u6,
"name98=value98; =; token=",
new Cookie[]
@@ -189,7 +195,8 @@ namespace System.Net.Primitives.Unit.Tests
}
}; // Ignore invalid tokens
yield return new object[] {
yield return new object[]
{
u6,
"name98=\"value; domain=\".domain\"; max-age=\"400\"",
new Cookie[]
@@ -198,7 +205,8 @@ namespace System.Net.Primitives.Unit.Tests
}
}; // Use escaped values (1)
yield return new object[] {
yield return new object[]
{
u6,
"name98=\"\"",
new Cookie[]
@@ -206,6 +214,123 @@ namespace System.Net.Primitives.Unit.Tests
new Cookie("name98", "\"\"")
}
}; // Use escaped values (2)
yield return new object[]
{
u,
"locale=en, uuid=4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46, country=US, _m_ask_fm_session=session1",
new Cookie[]
{
new Cookie("locale", "en"),
new Cookie("uuid", "4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46"),
new Cookie("country", "US"),
new Cookie("_m_ask_fm_session", "session1")
}
}; // Normal case
yield return new object[]
{
uSecure,
"locale=en, uuid=4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46, country=US, _m_ask_fm_session=session1",
new Cookie[]
{
new Cookie("locale", "en"),
new Cookie("uuid", "4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46"),
new Cookie("country", "US"),
new Cookie("_m_ask_fm_session", "session1")
}
}; // Normal case with secure URI
yield return new object[]
{
u,
",locale=en, uuid=4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46, country=US, _m_ask_fm_session=session1",
new Cookie[]
{
new Cookie("locale", "en"),
new Cookie("uuid", "4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46"),
new Cookie("country", "US"),
new Cookie("_m_ask_fm_session", "session1")
}
}; // Empty header at the beginning
yield return new object[]
{
uSecure,
" ,locale=en, uuid=4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46, country=US, _m_ask_fm_session=session1",
new Cookie[]
{
new Cookie("locale", "en"),
new Cookie("uuid", "4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46"),
new Cookie("country", "US"),
new Cookie("_m_ask_fm_session", "session1")
}
}; // Empty header composed of spaces at the beginning
yield return new object[]
{
u,
"locale=en,, uuid=4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46, country=US, _m_ask_fm_session=session1",
new Cookie[]
{
new Cookie("locale", "en"),
new Cookie("uuid", "4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46"),
new Cookie("country", "US"),
new Cookie("_m_ask_fm_session", "session1")
}
}; // Empty header in the middle
yield return new object[]
{
uSecure,
"locale=en, uuid=4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46, , country=US, _m_ask_fm_session=session1",
new Cookie[]
{
new Cookie("locale", "en"),
new Cookie("uuid", "4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46"),
new Cookie("country", "US"),
new Cookie("_m_ask_fm_session", "session1")
}
}; // Empty header composed of spaces in the middle
yield return new object[]
{
u,
"locale=en, uuid=4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46, country=US, _m_ask_fm_session=session1,",
new Cookie[]
{
new Cookie("locale", "en"),
new Cookie("uuid", "4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46"),
new Cookie("country", "US"),
new Cookie("_m_ask_fm_session", "session1")
}
}; // Empty header at the end
yield return new object[]
{
u,
"locale=en, uuid=4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46, country=US, _m_ask_fm_session=session1, ",
new Cookie[]
{
new Cookie("locale", "en"),
new Cookie("uuid", "4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46"),
new Cookie("country", "US"),
new Cookie("_m_ask_fm_session", "session1")
}
}; // Empty header composed of spaces at the end
yield return new object[]
{
uSecure,
"locale=en, uuid=4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46, country=US, _m_ask_fm_session=session1, ,",
new Cookie[]
{
new Cookie("locale", "en"),
new Cookie("uuid", "4b8b2dd7-d91a-49ee-80c6-8cb7df1fae46"),
new Cookie("country", "US"),
new Cookie("_m_ask_fm_session", "session1")
}
}; // Empty header followed by another empty header at the end
}
[Theory]
@@ -218,6 +343,7 @@ namespace System.Net.Primitives.Unit.Tests
[Theory]
[MemberData(nameof(SetCookiesData))]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix shipping in .NET 4.7.2")]
public void SetCookies_Success(Uri uri, string cookieHeader, Cookie[] expected)
{
CookieContainer cc = CreateCount11Container();
@@ -518,7 +644,6 @@ namespace System.Net.Primitives.Unit.Tests
}
[Fact]
[ActiveIssue(24368)]
public void GetCookies_DifferentPaths_ReturnsConsistentResults()
{
Cookie c1 = new Cookie("name1", "value", "/base", ".url.com");