Skip to content

Commit 386d88a

Browse files
authored
Merge pull request github#6085 from tamasvajk/feature/unsafe
C#: Fix `Modifiable::isUnsafe` to handle declarations extracted from assemblies
2 parents 847faf5 + 74c4765 commit 386d88a

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* The `Modifiable::isUnsafe` predicate has been fixed to handle symbols that are not extracted from source code.

csharp/ql/src/semmle/code/csharp/Member.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ class Modifiable extends Declaration, @modifiable {
8686
predicate isConst() { this.hasModifier("const") }
8787

8888
/** Holds if this declaration is `unsafe`. */
89-
predicate isUnsafe() { this.hasModifier("unsafe") }
89+
predicate isUnsafe() {
90+
this.hasModifier("unsafe") or
91+
this.(Parameterizable).getAParameter().getType() instanceof PointerType or
92+
this.(Property).getType() instanceof PointerType or
93+
this.(Callable).getReturnType() instanceof PointerType
94+
}
9095

9196
/** Holds if this declaration is `async`. */
9297
predicate isAsync() { this.hasModifier("async") }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import csharp
22

3-
select any(Modifiable m | m.isUnsafe())
3+
select any(Modifiable m | m.isUnsafe() and m.fromSource())

0 commit comments

Comments
 (0)