Infer# v1.2: 用于C#的程序间内存安全分析亮点展示

98 阅读1分钟

去年12月,我们宣布了Infer#的公开预览版,它将Infer的程序间静态分析带到了.NET社区。该项目在GitHub上以MIT许可的方式开放源代码

新功能亮点

Infer# 1.2带来了竞赛条件检测,提高了性能,提供了更多的使用方法,并扩大了分析范围。完整的改进列表可以在发布页面上找到。

通过WSL2(Windows Subsystem for Linux)支持Windows上的Infer#。

作为我们为Infer#提供Windows支持的第一步,你现在可以在WSL2中运行分析

Azure管道的整合

我们现在支持Infer#作为Azure Pipelines插件

竞赛条件

Infer#现在支持通过Infer的RacerD分析器进行竞赛条件检测:

public class RaceCondition
{
    private readonly object _object = new object();

    public void TestMethod()
    {
        int FirstLocal;
        FirstLocal = TestClass.StaticIntegerField;
    }

    public void FieldWrite()
    {
        lock (_object)
        {
            {
                TestClass.StaticIntegerField = 1;
            }
        }
    }
}
Assets/RaceCondition.cs:12: warning: Thread Safety Violation
  Read/Write race. Non-private method `RaceCondition.TestMethod()` reads without synchronization from `Assets.TestClass.Cilsil.Test.Assets.TestClass.StaticIntegerField`. Potentially races with write in method `RaceCondition.FieldWrite()`.
 Reporting because another access to the same memory occurs on a background thread, although this access may not.

异常代码覆盖

现在,Infer#对具有异常处理结构的方法(例如,try-catch-finally和lock)报告警告:

public void ResourceLeakExcepHandlingBad() {
    StreamWriter stream = AllocateStreamWriter();
    try
    {
        stream.WriteLine(12);
    }
    catch
    {
        Console.WriteLine("Fail to write");
    }
    finally
    {
        // FIXME: should close the stream by calling stream.Close().
    }
}
/.../Examples/Program.cs:39: error: Dotnet Resource Leak
  Leaked { %0 -> 1 } resource(s) at type(s) System.IO.StreamWriter.

使用Infer#

你可以在我们的GitHub登陆页面上找到所有支持场景的说明。

请向我们的GitHub仓库提交你的反馈和功能请求。我们正在关注来自社区的所有功能请求,并将根据受欢迎程度来确定下一步的优先次序。