Skip to content

Commit

Permalink
Merge pull request #104565 from dotnet/merge/release/6.0-to-release/6…
Browse files Browse the repository at this point in the history
….0-staging

[automated] Merge branch 'release/6.0' => 'release/6.0-staging'
  • Loading branch information
carlossanlop authored Jul 15, 2024
2 parents 2ac8b5f + b2d2bd3 commit 50f436d
Show file tree
Hide file tree
Showing 23 changed files with 662 additions and 123 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/inter-branch-merge-flow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Inter-branch merge workflow
on:
push:
branches:
- release/**

permissions:
contents: write
pull-requests: write

jobs:
Merge:
uses: dotnet/arcade/.github/workflows/inter-branch-merge-base.yml@main
5 changes: 5 additions & 0 deletions src/coreclr/debug/createdump/createdump.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,10 @@ typedef struct
extern bool CreateDump(const CreateDumpOptions& options);
extern bool FormatDumpName(std::string& name, const char* pattern, const char* exename, int pid);

#ifdef HOST_WINDOWS
extern DWORD GetTempPathWrapper(IN DWORD nBufferLength, OUT LPSTR lpBuffer);
#else
#define GetTempPathWrapper GetTempPathA
#endif
extern void printf_status(const char* format, ...);
extern void printf_error(const char* format, ...);
35 changes: 35 additions & 0 deletions src/coreclr/debug/createdump/createdumpwindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,38 @@ CreateDump(const CreateDumpOptions& options)

return result;
}

typedef DWORD(WINAPI *pfnGetTempPathA)(DWORD nBufferLength, LPSTR lpBuffer);

static volatile pfnGetTempPathA
g_pfnGetTempPathA = nullptr;


DWORD
GetTempPathWrapper(
IN DWORD nBufferLength,
OUT LPSTR lpBuffer)
{
if (g_pfnGetTempPathA == nullptr)
{
HMODULE hKernel32 = LoadLibraryExW(L"kernel32.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);

pfnGetTempPathA pLocalGetTempPathA = NULL;
if (hKernel32 != NULL)
{
// store to thread local variable to prevent data race
pLocalGetTempPathA = (pfnGetTempPathA)::GetProcAddress(hKernel32, "GetTempPath2A");
}

if (pLocalGetTempPathA == NULL) // method is only available with Windows 10 Creators Update or later
{
g_pfnGetTempPathA = &GetTempPathA;
}
else
{
g_pfnGetTempPathA = pLocalGetTempPathA;
}
}

return g_pfnGetTempPathA(nBufferLength, lpBuffer);
}
2 changes: 1 addition & 1 deletion src/coreclr/debug/createdump/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int __cdecl main(const int argc, const char* argv[])

if (options.DumpPathTemplate == nullptr)
{
if (::GetTempPathA(MAX_LONGPATH, tmpPath) == 0)
if (::GetTempPathWrapper(MAX_LONGPATH, tmpPath) == 0)
{
printf_error("GetTempPath failed (0x%08x)\n", ::GetLastError());
return ::GetLastError();
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/inc/longfilepathwrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ UINT WINAPI GetTempFileNameWrapper(
SString& lpTempFileName
);

DWORD WINAPI GetTempPathWrapper(
SString& lpBuffer
);

DWORD WINAPI GetCurrentDirectoryWrapper(
SString& lpBuffer
);
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/inc/winwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@
//Long Files will not work on these till redstone
#define WszGetCurrentDirectory GetCurrentDirectoryWrapper
#define WszGetTempFileName GetTempFileNameWrapper
#define WszGetTempPath GetTempPathWrapper

//APIS which have a buffer as an out parameter
#define WszGetEnvironmentVariable GetEnvironmentVariableWrapper
Expand Down
40 changes: 0 additions & 40 deletions src/coreclr/utilcode/longfilepathwrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,46 +514,6 @@ UINT WINAPI GetTempFileNameWrapper(

return ret;
}
DWORD WINAPI GetTempPathWrapper(
SString& lpBuffer
)
{
CONTRACTL
{
NOTHROW;
}
CONTRACTL_END;

HRESULT hr = S_OK;
DWORD ret = 0;
DWORD lastError;

EX_TRY
{
//Change the behaviour in Redstone to retry
COUNT_T size = MAX_LONGPATH;

ret = GetTempPathW(
size,
lpBuffer.OpenUnicodeBuffer(size - 1)
);

lastError = GetLastError();
lpBuffer.CloseBuffer(ret);
}
EX_CATCH_HRESULT(hr);

if (hr != S_OK)
{
SetLastError(hr);
}
else if (ret == 0)
{
SetLastError(lastError);
}

return ret;
}

DWORD WINAPI GetCurrentDirectoryWrapper(
SString& lpBuffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
#if !MS_IO_REDIST // SafeLibraryHandle is inaccessible due to its protection level
[DllImport(Libraries.Kernel32, CharSet = CharSet.Ansi, BestFitMapping = false)]
public static extern IntPtr GetProcAddress(SafeLibraryHandle hModule, string lpProcName);
#endif

[DllImport(Libraries.Kernel32, CharSet = CharSet.Ansi, BestFitMapping = false)]
public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ internal static partial class Kernel32
{
[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)]
internal static extern uint GetTempPathW(int bufferLen, ref char buffer);

[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)]
internal static extern uint GetTempPath2W(int bufferLen, ref char buffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ internal static void ReadDsaPrivateKey(
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
}

DssParms parms = DssParms.Decode(algId.Parameters.Value, AsnEncodingRules.BER);

ret = new DSAParameters
{
P = parms.P.ToByteArray(isUnsigned: true, isBigEndian: true),
Q = parms.Q.ToByteArray(isUnsigned: true, isBigEndian: true),
};

ret.G = parms.G.ExportKeyParameter(ret.P.Length);

BigInteger x;

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

DssParms parms = DssParms.Decode(algId.Parameters.Value, AsnEncodingRules.BER);

// Sanity checks from FIPS 186-4 4.1/4.2. Since FIPS 186-5 withdrew DSA/DSS
// these will never change again.
//
// This technically allows a non-standard combination of 1024-bit P and 256-bit Q,
// but that will get filtered out by the underlying provider.
// These checks just prevent obviously bad data from wasting work on reinterpretation.

if (parms.P.Sign < 0 ||
parms.Q.Sign < 0 ||
!IsValidPLength(parms.P.GetBitLength()) ||
!IsValidQLength(parms.Q.GetBitLength()) ||
parms.G <= 1 ||
parms.G >= parms.P ||
x <= 1 ||
x >= parms.Q)
{
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
}

ret = new DSAParameters
{
P = parms.P.ToByteArray(isUnsigned: true, isBigEndian: true),
Q = parms.Q.ToByteArray(isUnsigned: true, isBigEndian: true),
};

ret.G = parms.G.ExportKeyParameter(ret.P.Length);
ret.X = x.ExportKeyParameter(ret.Q.Length);

// The public key is not contained within the format, calculate it.
Expand All @@ -69,6 +87,11 @@ internal static void ReadDsaPublicKey(
in AlgorithmIdentifierAsn algId,
out DSAParameters ret)
{
if (!algId.Parameters.HasValue)
{
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
}

BigInteger y;

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

if (!algId.Parameters.HasValue)
DssParms parms = DssParms.Decode(algId.Parameters.Value, AsnEncodingRules.BER);

// Sanity checks from FIPS 186-4 4.1/4.2. Since FIPS 186-5 withdrew DSA/DSS
// these will never change again.
//
// This technically allows a non-standard combination of 1024-bit P and 256-bit Q,
// but that will get filtered out by the underlying provider.
// These checks just prevent obviously bad data from wasting work on reinterpretation.

if (parms.P.Sign < 0 ||
parms.Q.Sign < 0 ||
!IsValidPLength(parms.P.GetBitLength()) ||
!IsValidQLength(parms.Q.GetBitLength()) ||
parms.G <= 1 ||
parms.G >= parms.P ||
y <= 1 ||
y >= parms.P)
{
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
}

DssParms parms = DssParms.Decode(algId.Parameters.Value, AsnEncodingRules.BER);

ret = new DSAParameters
{
P = parms.P.ToByteArray(isUnsigned: true, isBigEndian: true),
Expand All @@ -105,6 +142,25 @@ internal static void ReadDsaPublicKey(
ret.Y = y.ExportKeyParameter(ret.P.Length);
}

private static bool IsValidPLength(long pBitLength)
{
return pBitLength switch
{
// FIPS 186-3/186-4
1024 or 2048 or 3072 => true,
// FIPS 186-1/186-2
>= 512 and < 1024 => pBitLength % 64 == 0,
_ => false,
};
}

private static bool IsValidQLength(long qBitLength)
{
// FIPS 196-1/186-2 only allows 160
// FIPS 186-3/186-4 allow 160/224/256
return qBitLength is 160 or 224 or 256;
}

internal static void ReadSubjectPublicKeyInfo(
ReadOnlySpan<byte> source,
out int bytesRead,
Expand Down
Loading

0 comments on commit 50f436d

Please sign in to comment.