Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hash with sha2 for mutex lock #14777

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,12 @@ private void SessionEndedHandler(object? sender, SessionEndEventArgs args)
// The name of the file starts with the process name, that's the only filtering we can do.
// So there's one possible benign race condition when another test is dumping an host and we take lock on the name but the dump is not finished.
// In that case we'll fail for file locking but it's fine. The correct or subsequent "SessionEndedHandler" will move that one.
using MD5 md5LockName = MD5.Create();
// BitConverter converts into something like EC-1B-B6-22-81-00-41-C8-31-1D-B6-61-27-6A-65-8A valid muxer name
using SHA256 hashedLockName = SHA256.Create();
// LPCSTR An LPCSTR is a 32-bit pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters.
string muxerName = @$"Global\{BitConverter.ToString(md5LockName.ComputeHash(Encoding.UTF8.GetBytes(dumpFileNameFullPath)))}";
var toGuid = new byte[16];
Array.Copy(hashedLockName.ComputeHash(Encoding.UTF8.GetBytes(dumpFileNameFullPath)), toGuid, 16);
Guid id = new(toGuid);
string muxerName = @$"Global\{id}";
using Mutex lockFile = new(true, muxerName, out bool createdNew);
EqtTrace.Info($"[MonitorPostmortemDump]Acquired global muxer '{muxerName}' for {dumpFileNameFullPath}");
if (createdNew)
Expand Down