Skip to content

Commit 50f436d

Browse files
authored
Merge pull request #104565 from dotnet/merge/release/6.0-to-release/6.0-staging
[automated] Merge branch 'release/6.0' => 'release/6.0-staging'
2 parents 2ac8b5f + b2d2bd3 commit 50f436d

File tree

23 files changed

+662
-123
lines changed

23 files changed

+662
-123
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Inter-branch merge workflow
2+
on:
3+
push:
4+
branches:
5+
- release/**
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
Merge:
13+
uses: dotnet/arcade/.github/workflows/inter-branch-merge-base.yml@main

src/coreclr/debug/createdump/createdump.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,10 @@ typedef struct
132132
extern bool CreateDump(const CreateDumpOptions& options);
133133
extern bool FormatDumpName(std::string& name, const char* pattern, const char* exename, int pid);
134134

135+
#ifdef HOST_WINDOWS
136+
extern DWORD GetTempPathWrapper(IN DWORD nBufferLength, OUT LPSTR lpBuffer);
137+
#else
138+
#define GetTempPathWrapper GetTempPathA
139+
#endif
135140
extern void printf_status(const char* format, ...);
136141
extern void printf_error(const char* format, ...);

src/coreclr/debug/createdump/createdumpwindows.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,38 @@ CreateDump(const CreateDumpOptions& options)
7373

7474
return result;
7575
}
76+
77+
typedef DWORD(WINAPI *pfnGetTempPathA)(DWORD nBufferLength, LPSTR lpBuffer);
78+
79+
static volatile pfnGetTempPathA
80+
g_pfnGetTempPathA = nullptr;
81+
82+
83+
DWORD
84+
GetTempPathWrapper(
85+
IN DWORD nBufferLength,
86+
OUT LPSTR lpBuffer)
87+
{
88+
if (g_pfnGetTempPathA == nullptr)
89+
{
90+
HMODULE hKernel32 = LoadLibraryExW(L"kernel32.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
91+
92+
pfnGetTempPathA pLocalGetTempPathA = NULL;
93+
if (hKernel32 != NULL)
94+
{
95+
// store to thread local variable to prevent data race
96+
pLocalGetTempPathA = (pfnGetTempPathA)::GetProcAddress(hKernel32, "GetTempPath2A");
97+
}
98+
99+
if (pLocalGetTempPathA == NULL) // method is only available with Windows 10 Creators Update or later
100+
{
101+
g_pfnGetTempPathA = &GetTempPathA;
102+
}
103+
else
104+
{
105+
g_pfnGetTempPathA = pLocalGetTempPathA;
106+
}
107+
}
108+
109+
return g_pfnGetTempPathA(nBufferLength, lpBuffer);
110+
}

src/coreclr/debug/createdump/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ int __cdecl main(const int argc, const char* argv[])
175175

176176
if (options.DumpPathTemplate == nullptr)
177177
{
178-
if (::GetTempPathA(MAX_LONGPATH, tmpPath) == 0)
178+
if (::GetTempPathWrapper(MAX_LONGPATH, tmpPath) == 0)
179179
{
180180
printf_error("GetTempPath failed (0x%08x)\n", ::GetLastError());
181181
return ::GetLastError();

src/coreclr/inc/longfilepathwrappers.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ UINT WINAPI GetTempFileNameWrapper(
8787
SString& lpTempFileName
8888
);
8989

90-
DWORD WINAPI GetTempPathWrapper(
91-
SString& lpBuffer
92-
);
93-
9490
DWORD WINAPI GetCurrentDirectoryWrapper(
9591
SString& lpBuffer
9692
);

src/coreclr/inc/winwrap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@
220220
//Long Files will not work on these till redstone
221221
#define WszGetCurrentDirectory GetCurrentDirectoryWrapper
222222
#define WszGetTempFileName GetTempFileNameWrapper
223-
#define WszGetTempPath GetTempPathWrapper
224223

225224
//APIS which have a buffer as an out parameter
226225
#define WszGetEnvironmentVariable GetEnvironmentVariableWrapper

src/coreclr/utilcode/longfilepathwrappers.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -514,46 +514,6 @@ UINT WINAPI GetTempFileNameWrapper(
514514

515515
return ret;
516516
}
517-
DWORD WINAPI GetTempPathWrapper(
518-
SString& lpBuffer
519-
)
520-
{
521-
CONTRACTL
522-
{
523-
NOTHROW;
524-
}
525-
CONTRACTL_END;
526-
527-
HRESULT hr = S_OK;
528-
DWORD ret = 0;
529-
DWORD lastError;
530-
531-
EX_TRY
532-
{
533-
//Change the behaviour in Redstone to retry
534-
COUNT_T size = MAX_LONGPATH;
535-
536-
ret = GetTempPathW(
537-
size,
538-
lpBuffer.OpenUnicodeBuffer(size - 1)
539-
);
540-
541-
lastError = GetLastError();
542-
lpBuffer.CloseBuffer(ret);
543-
}
544-
EX_CATCH_HRESULT(hr);
545-
546-
if (hr != S_OK)
547-
{
548-
SetLastError(hr);
549-
}
550-
else if (ret == 0)
551-
{
552-
SetLastError(lastError);
553-
}
554-
555-
return ret;
556-
}
557517

558518
DWORD WINAPI GetCurrentDirectoryWrapper(
559519
SString& lpBuffer

src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetProcAddress.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ internal static partial class Interop
1010
{
1111
internal static partial class Kernel32
1212
{
13+
#if !MS_IO_REDIST // SafeLibraryHandle is inaccessible due to its protection level
1314
[DllImport(Libraries.Kernel32, CharSet = CharSet.Ansi, BestFitMapping = false)]
1415
public static extern IntPtr GetProcAddress(SafeLibraryHandle hModule, string lpProcName);
16+
#endif
1517

1618
[DllImport(Libraries.Kernel32, CharSet = CharSet.Ansi, BestFitMapping = false)]
1719
public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);

src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetTempPathW.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ internal static partial class Kernel32
99
{
1010
[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)]
1111
internal static extern uint GetTempPathW(int bufferLen, ref char buffer);
12+
13+
[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)]
14+
internal static extern uint GetTempPath2W(int bufferLen, ref char buffer);
1215
}
1316
}

src/libraries/Common/src/System/Security/Cryptography/DSAKeyFormatHelper.cs

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ internal static void ReadDsaPrivateKey(
2525
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
2626
}
2727

28-
DssParms parms = DssParms.Decode(algId.Parameters.Value, AsnEncodingRules.BER);
29-
30-
ret = new DSAParameters
31-
{
32-
P = parms.P.ToByteArray(isUnsigned: true, isBigEndian: true),
33-
Q = parms.Q.ToByteArray(isUnsigned: true, isBigEndian: true),
34-
};
35-
36-
ret.G = parms.G.ExportKeyParameter(ret.P.Length);
37-
3828
BigInteger x;
3929

4030
try
@@ -57,6 +47,34 @@ internal static void ReadDsaPrivateKey(
5747
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding, e);
5848
}
5949

50+
DssParms parms = DssParms.Decode(algId.Parameters.Value, AsnEncodingRules.BER);
51+
52+
// Sanity checks from FIPS 186-4 4.1/4.2. Since FIPS 186-5 withdrew DSA/DSS
53+
// these will never change again.
54+
//
55+
// This technically allows a non-standard combination of 1024-bit P and 256-bit Q,
56+
// but that will get filtered out by the underlying provider.
57+
// These checks just prevent obviously bad data from wasting work on reinterpretation.
58+
59+
if (parms.P.Sign < 0 ||
60+
parms.Q.Sign < 0 ||
61+
!IsValidPLength(parms.P.GetBitLength()) ||
62+
!IsValidQLength(parms.Q.GetBitLength()) ||
63+
parms.G <= 1 ||
64+
parms.G >= parms.P ||
65+
x <= 1 ||
66+
x >= parms.Q)
67+
{
68+
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
69+
}
70+
71+
ret = new DSAParameters
72+
{
73+
P = parms.P.ToByteArray(isUnsigned: true, isBigEndian: true),
74+
Q = parms.Q.ToByteArray(isUnsigned: true, isBigEndian: true),
75+
};
76+
77+
ret.G = parms.G.ExportKeyParameter(ret.P.Length);
6078
ret.X = x.ExportKeyParameter(ret.Q.Length);
6179

6280
// The public key is not contained within the format, calculate it.
@@ -69,6 +87,11 @@ internal static void ReadDsaPublicKey(
6987
in AlgorithmIdentifierAsn algId,
7088
out DSAParameters ret)
7189
{
90+
if (!algId.Parameters.HasValue)
91+
{
92+
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
93+
}
94+
7295
BigInteger y;
7396

7497
try
@@ -88,13 +111,27 @@ internal static void ReadDsaPublicKey(
88111
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding, e);
89112
}
90113

91-
if (!algId.Parameters.HasValue)
114+
DssParms parms = DssParms.Decode(algId.Parameters.Value, AsnEncodingRules.BER);
115+
116+
// Sanity checks from FIPS 186-4 4.1/4.2. Since FIPS 186-5 withdrew DSA/DSS
117+
// these will never change again.
118+
//
119+
// This technically allows a non-standard combination of 1024-bit P and 256-bit Q,
120+
// but that will get filtered out by the underlying provider.
121+
// These checks just prevent obviously bad data from wasting work on reinterpretation.
122+
123+
if (parms.P.Sign < 0 ||
124+
parms.Q.Sign < 0 ||
125+
!IsValidPLength(parms.P.GetBitLength()) ||
126+
!IsValidQLength(parms.Q.GetBitLength()) ||
127+
parms.G <= 1 ||
128+
parms.G >= parms.P ||
129+
y <= 1 ||
130+
y >= parms.P)
92131
{
93132
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
94133
}
95134

96-
DssParms parms = DssParms.Decode(algId.Parameters.Value, AsnEncodingRules.BER);
97-
98135
ret = new DSAParameters
99136
{
100137
P = parms.P.ToByteArray(isUnsigned: true, isBigEndian: true),
@@ -105,6 +142,25 @@ internal static void ReadDsaPublicKey(
105142
ret.Y = y.ExportKeyParameter(ret.P.Length);
106143
}
107144

145+
private static bool IsValidPLength(long pBitLength)
146+
{
147+
return pBitLength switch
148+
{
149+
// FIPS 186-3/186-4
150+
1024 or 2048 or 3072 => true,
151+
// FIPS 186-1/186-2
152+
>= 512 and < 1024 => pBitLength % 64 == 0,
153+
_ => false,
154+
};
155+
}
156+
157+
private static bool IsValidQLength(long qBitLength)
158+
{
159+
// FIPS 196-1/186-2 only allows 160
160+
// FIPS 186-3/186-4 allow 160/224/256
161+
return qBitLength is 160 or 224 or 256;
162+
}
163+
108164
internal static void ReadSubjectPublicKeyInfo(
109165
ReadOnlySpan<byte> source,
110166
out int bytesRead,

0 commit comments

Comments
 (0)