-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C#: Tolerate missing call targets in LogMessageSink #14855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
csharp/ql/test/library-tests/standalone/externalLocationSink/externalLocationSink.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#select | ||
| standalone.cs:20:20:20:20 | access to parameter s | standalone.cs:20:20:20:20 | access to parameter s | | ||
| standalone.cs:25:28:25:32 | "abc" | standalone.cs:25:28:25:32 | "abc" | | ||
compilationErrors | ||
| standalone.cs:16:12:16:18 | CS0104: 'ILogger' is an ambiguous reference between 'A.ILogger' and 'B.ILogger' | | ||
methodCalls | ||
| standalone.cs:20:9:20:21 | call to method | | ||
| standalone.cs:25:9:25:33 | call to method | |
10 changes: 10 additions & 0 deletions
10
csharp/ql/test/library-tests/standalone/externalLocationSink/externalLocationSink.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import semmle.code.csharp.security.dataflow.flowsinks.ExternalLocationSink | ||
import semmle.code.csharp.commons.Diagnostics | ||
|
||
from ExternalLocationSink sink | ||
where sink.getLocation().getFile().fromSource() | ||
select sink, sink.getExpr() | ||
|
||
query predicate compilationErrors(CompilerError e) { any() } | ||
|
||
query predicate methodCalls(MethodCall m) { any() } |
1 change: 1 addition & 0 deletions
1
csharp/ql/test/library-tests/standalone/externalLocationSink/options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
semmle-extractor-options: --standalone |
27 changes: 27 additions & 0 deletions
27
csharp/ql/test/library-tests/standalone/externalLocationSink/standalone.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using A; | ||
using B; | ||
|
||
namespace A | ||
{ | ||
public interface ILogger { } | ||
} | ||
|
||
namespace B | ||
{ | ||
public interface ILogger { } | ||
} | ||
|
||
public class C | ||
{ | ||
public ILogger logger; | ||
|
||
private void M(string s) | ||
{ | ||
logger.Log(s); | ||
} | ||
|
||
private static void Main() | ||
{ | ||
new C().logger.Log("abc"); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOI, which type does Roslyn then assign to this field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case it's
A.ILogger
. What's odd is that when we process the field, there's no sign of ambiguity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's also what I don't understand, I would have expected that Roslyn didn't assign any type at all. Or is it perhaps because we just take the first candidate symbol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To conclude, we found that there's no ambiguity when processing the field or the reference to the field. But the field's type symbol is actually an ambiguous error symbol.