Skip to content

Mutex name null causes FailFast in chk on Unix #24558

@danmoseley

Description

@danmoseley

This caused a test failure in CoreCLR CI:

  FailFast: 
  
     at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage) in /mnt/j/workspace/dotnet_coreclr/master/jitstress/x64_checked_ubuntu_corefx_baseline_prtest/src/mscorlib/shared/System/Diagnostics/Debug.cs:line 97
     at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew) in /mnt/j/workspace/dotnet_coreclr/master/jitstress/x64_checked_ubuntu_corefx_baseline_prtest/src/mscorlib/src/System/Threading/Mutex.cs:line 108
     at System.IO.IsolatedStorage.Helper.CreateMutexNotOwned(String pathName) in /mnt/j/workspace/dotnet_coreclr/master/jitstress/x64_checked_ubuntu_corefx_baseline_prtest/_/fx/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs:line 146
     at System.IO.IsolatedStorage.Helper.GetRandomDirectory(String rootDirectory, IsolatedStorageScope scope) in /mnt/j/workspace/dotnet_coreclr/master/jitstress/x64_checked_ubuntu_corefx_baseline_prtest/_/fx/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs:line 86

dotnet/coreclr#14181 left a Debug.Assert upstream of the ArgumentException:

        private void CreateMutexCore(bool initiallyOwned, string name, out bool createdNew)
        {
            Debug.Assert(name == null || name.Length <= Path.MaxPath);

            uint mutexFlags = initiallyOwned ? Win32Native.CREATE_MUTEX_INITIAL_OWNER : 0;

            SafeWaitHandle mutexHandle = Win32Native.CreateMutexEx(null, name, mutexFlags, AccessRights);
            int errorCode = Marshal.GetLastWin32Error();

            if (mutexHandle.IsInvalid)
            {
                mutexHandle.SetHandleAsInvalid();
#if PLATFORM_UNIX
                if (errorCode == Interop.Errors.ERROR_FILENAME_EXCED_RANGE)
                    // On Unix, length validation is done by CoreCLR's PAL after converting to utf-8
                    throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, Interop.Sys.MaxName), nameof(name));
#endif

The fix may be to remove the assert (if the resulting error for null is also acceptable). Plus make sure we have for long and null mutex names in both Unix and Windows.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions