summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuri Vanin <yvanin@users.noreply.github.com>2017-11-06 10:20:02 -0800
committerDan Moseley <danmose@microsoft.com>2017-11-06 10:20:02 -0800
commit65cf3deb784647c01af77b046a8d907a9a02fdce (patch)
tree850843f2bf7f01ce29133e320d6d57b0738d814d /src
parent719b5970cfc08ba47edb058758c3c6c9525804c6 (diff)
downloadcoreclr-65cf3deb784647c01af77b046a8d907a9a02fdce.tar.gz
coreclr-65cf3deb784647c01af77b046a8d907a9a02fdce.tar.bz2
coreclr-65cf3deb784647c01af77b046a8d907a9a02fdce.zip
Allow any string length in Environment.SetEnvironmentVariable (#14872)
Fix for CoreFX #16766
Diffstat (limited to 'src')
-rw-r--r--src/mscorlib/src/Microsoft/Win32/Win32Native.cs1
-rw-r--r--src/mscorlib/src/System/Environment.cs15
2 files changed, 5 insertions, 11 deletions
diff --git a/src/mscorlib/src/Microsoft/Win32/Win32Native.cs b/src/mscorlib/src/Microsoft/Win32/Win32Native.cs
index dab609fcb6..4e47ecce58 100644
--- a/src/mscorlib/src/Microsoft/Win32/Win32Native.cs
+++ b/src/mscorlib/src/Microsoft/Win32/Win32Native.cs
@@ -617,6 +617,7 @@ namespace Microsoft.Win32
internal const int ERROR_BAD_IMPERSONATION_LEVEL = 0x542;
internal const int ERROR_CANT_OPEN_ANONYMOUS = 0x543;
internal const int ERROR_NO_SECURITY_ON_OBJECT = 0x546;
+ internal const int ERROR_NO_SYSTEM_RESOURCES = 0x5AA;
internal const int ERROR_TRUSTED_RELATIONSHIP_FAILURE = 0x6FD;
// Error codes from ntstatus.h
diff --git a/src/mscorlib/src/System/Environment.cs b/src/mscorlib/src/System/Environment.cs
index f230577fac..f7e4e923d6 100644
--- a/src/mscorlib/src/System/Environment.cs
+++ b/src/mscorlib/src/System/Environment.cs
@@ -42,7 +42,7 @@ namespace System
internal static partial class Environment
{
// Assume the following constants include the terminating '\0' - use <, not <=
- private const int MaxEnvVariableValueLength = 32767; // maximum length for environment variable name and value
+
// System environment variables are stored in the registry, and have
// a size restriction that is separate from both normal environment
// variables and registry value name lengths, according to MSDN.
@@ -476,8 +476,6 @@ namespace System
private static void ValidateVariableAndValue(string variable, ref string value)
{
- const int MaxEnvVariableValueLength = 32767;
-
if (variable == null)
{
throw new ArgumentNullException(nameof(variable));
@@ -490,10 +488,6 @@ namespace System
{
throw new ArgumentException(SR.Argument_StringFirstCharIsZero, nameof(variable));
}
- if (variable.Length >= MaxEnvVariableValueLength)
- {
- throw new ArgumentException(SR.Argument_LongEnvVarValue, nameof(variable));
- }
if (variable.IndexOf('=') != -1)
{
throw new ArgumentException(SR.Argument_IllegalEnvVarName, nameof(variable));
@@ -504,10 +498,6 @@ namespace System
// Explicitly null out value if it's empty
value = null;
}
- else if (value.Length >= MaxEnvVariableValueLength)
- {
- throw new ArgumentException(SR.Argument_LongEnvVarValue, nameof(value));
- }
}
private static void ValidateTarget(EnvironmentVariableTarget target)
@@ -703,6 +693,9 @@ namespace System
// The error message from Win32 is "The filename or extension is too long",
// which is not accurate.
throw new ArgumentException(SR.Format(SR.Argument_LongEnvVarValue));
+ case Win32Native.ERROR_NOT_ENOUGH_MEMORY:
+ case Win32Native.ERROR_NO_SYSTEM_RESOURCES:
+ throw new OutOfMemoryException(Interop.Kernel32.GetMessage(errorCode));
default:
throw new ArgumentException(Interop.Kernel32.GetMessage(errorCode));
}