gpt4 book ai didi

c# - Semgrep 找不到带有 'patterns' 部分的两行代码

转载 作者:行者123 更新时间:2023-12-05 03:27:32 25 4
gpt4 key购买 nike

我有一个 Semgrep 规则:

rules:
- id: create-chat-client
patterns:
- pattern: var $X = GrpcChannel.ForAddress(...);
- pattern: var $Y = new ChatService.ChatServiceClient($X);
languages:
- csharp
message: <pass>
severity: INFO

我正在尝试匹配这段代码:

using Grpc.Net.Client;
using GrpcChat.ProtoBuf;

var channel = GrpcChannel.ForAddress("https://localhost:8888");
var client = new ChatService.ChatServiceClient(channel);

这些分别匹配,但“模式”应该是“AND”匹配,但失败了。我一定错过了一些明显的东西。有人看到了什么吗?

最佳答案

使用 pattern-inside 有效:

rules:
- id: chat
patterns:
- pattern-inside: |
var $X = GrpcChannel.ForAddress(...);
...
- pattern: var $Y = new ChatService.ChatServiceClient($X);
languages:
- csharp
message: <pass>
severity: INFO

使用这个测试用例:

using Grpc.Net.Client;
using GrpcChat.ProtoBuf;

var channel = GrpcChannel.ForAddress("https://localhost:8888");
// ruleid: chat
var client = new ChatService.ChatServiceClient(channel);

当我运行测试时:

% semgrep --test rules/
✓ All tests passed!

关于c# - Semgrep 找不到带有 'patterns' 部分的两行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71459777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com