Skip to content

Commit ace633c

Browse files
authored
Merge pull request #14855 from tamasvajk/standalone/logMessageSink
C#: Tolerate missing call targets in LogMessageSink
2 parents 4f7fde7 + 253c658 commit ace633c

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsinks/ExternalLocationSink.qll

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ private class ExternalModelSink extends ExternalLocationSink {
2727
*/
2828
class LogMessageSink extends ExternalLocationSink {
2929
LogMessageSink() {
30-
this.getExpr() = any(LoggerType i).getAMethod().getACall().getAnArgument()
31-
or
30+
this.getExpr() = any(LoggerType i).getAMethod().getACall().getAnArgument() or
31+
this.getExpr() =
32+
any(MethodCall call | call.getQualifier().getType() instanceof LoggerType).getAnArgument() or
3233
this.getExpr() =
3334
any(ExtensionMethodCall call |
3435
call.getTarget().(ExtensionMethod).getExtendedType() instanceof LoggerType
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#select
2+
| standalone.cs:20:20:20:20 | access to parameter s | standalone.cs:20:20:20:20 | access to parameter s |
3+
| standalone.cs:25:28:25:32 | "abc" | standalone.cs:25:28:25:32 | "abc" |
4+
compilationErrors
5+
| standalone.cs:16:12:16:18 | CS0104: 'ILogger' is an ambiguous reference between 'A.ILogger' and 'B.ILogger' |
6+
methodCalls
7+
| standalone.cs:20:9:20:21 | call to method |
8+
| standalone.cs:25:9:25:33 | call to method |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import semmle.code.csharp.security.dataflow.flowsinks.ExternalLocationSink
2+
import semmle.code.csharp.commons.Diagnostics
3+
4+
from ExternalLocationSink sink
5+
where sink.getLocation().getFile().fromSource()
6+
select sink, sink.getExpr()
7+
8+
query predicate compilationErrors(CompilerError e) { any() }
9+
10+
query predicate methodCalls(MethodCall m) { any() }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: --standalone
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using A;
2+
using B;
3+
4+
namespace A
5+
{
6+
public interface ILogger { }
7+
}
8+
9+
namespace B
10+
{
11+
public interface ILogger { }
12+
}
13+
14+
public class C
15+
{
16+
public ILogger logger;
17+
18+
private void M(string s)
19+
{
20+
logger.Log(s);
21+
}
22+
23+
private static void Main()
24+
{
25+
new C().logger.Log("abc");
26+
}
27+
}

0 commit comments

Comments
 (0)