首页 > 解决方案 > 由于互斥锁导致的不正确锁定漏洞?

问题描述

Checkmarx 定期扫描我的 windows 项目。

现在,我得到

“不当_锁定”

我认为由于错误的 Mutex 实现导致的漏洞。

下面是 Mutex 的代码片段:

  Mutex TuningClientInstanceMutex;

  /// <summary>
  /// Method used to configure the inter process communication
  /// </summary>
  private void ConfigureInterProcessCommunication()
  {
     try
     {
        // Try to open existing mutex
        Mutex.OpenExisting(Mutex_Name);

        // Tuning Client must be already running
        return;
     }
     catch (WaitHandleCannotBeOpenedException)
     {
        // Not implemented.
     }

     // Flag that the application is available to accept automated calls
     // Create the mutex that will allow automated listeners to know that we have started
     TuningClientInstanceMutex= new Mutex(true, Mutex_Name);

     // Some other code is here.
     // ..........
     // ..........
  }

  public void Dispose()
  {
     if (TuningClientInstanceMutex!= null)
     {
        TuningClientInstanceMutex.Close();
     }
  }

我应该在这里改进什么来减轻“Improper_Locking”漏洞?

标签: c#.netmultithreadingmutexdispose

解决方案


推荐阅读