Skip to content

Commit 03f72d2

Browse files
author
Robert Marsh
committed
C++: use Declaration.hasGlobalOrStdName
1 parent bff68a0 commit 03f72d2

32 files changed

+138
-125
lines changed

cpp/ql/src/Critical/DescriptorMayNotBeClosed.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import semmle.code.cpp.pointsto.PointsTo
1313
import Negativity
1414

1515
predicate closeCall(FunctionCall fc, Variable v) {
16-
fc.getTarget().hasGlobalName("close") and v.getAnAccess() = fc.getArgument(0)
16+
fc.getTarget().hasGlobalOrStdName("close") and v.getAnAccess() = fc.getArgument(0)
1717
or
1818
exists(FunctionCall midcall, Function mid, int arg |
1919
fc.getArgument(arg) = v.getAnAccess() and

cpp/ql/src/Critical/DescriptorNeverClosed.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import semmle.code.cpp.pointsto.PointsTo
1313

1414
predicate closed(Expr e) {
1515
exists(FunctionCall fc |
16-
fc.getTarget().hasGlobalName("close") and
16+
fc.getTarget().hasGlobalOrStdName("close") and
1717
fc.getArgument(0) = e
1818
)
1919
}

cpp/ql/src/Critical/MemoryMayNotBeFreed.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ predicate allocCallOrIndirect(Expr e) {
5353
* can cause memory leaks.
5454
*/
5555
predicate verifiedRealloc(FunctionCall reallocCall, Variable v, ControlFlowNode verified) {
56-
reallocCall.getTarget().hasGlobalName("realloc") and
56+
reallocCall.getTarget().hasGlobalOrStdName("realloc") and
5757
reallocCall.getArgument(0) = v.getAnAccess() and
5858
(
5959
exists(Variable newV, ControlFlowNode node |
@@ -79,7 +79,7 @@ predicate verifiedRealloc(FunctionCall reallocCall, Variable v, ControlFlowNode
7979
predicate freeCallOrIndirect(ControlFlowNode n, Variable v) {
8080
// direct free call
8181
freeCall(n, v.getAnAccess()) and
82-
not n.(FunctionCall).getTarget().hasGlobalName("realloc")
82+
not n.(FunctionCall).getTarget().hasGlobalOrStdName("realloc")
8383
or
8484
// verified realloc call
8585
verifiedRealloc(_, v, n)

cpp/ql/src/Critical/OverflowCalculated.ql

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import cpp
1414

1515
class MallocCall extends FunctionCall {
1616
MallocCall() {
17-
this.getTarget().hasGlobalName("malloc") or
18-
this.getTarget().hasQualifiedName("std", "malloc")
17+
this.getTarget().hasGlobalOrStdName("malloc")
1918
}
2019

2120
Expr getAllocatedSize() {
@@ -36,12 +35,12 @@ predicate spaceProblem(FunctionCall append, string msg) {
3635
malloc.getAllocatedSize() = add and
3736
buffer.getAnAccess() = strlen.getStringExpr() and
3837
(
39-
insert.getTarget().hasGlobalName("strcpy") or
38+
insert.getTarget().hasGlobalOrStdName("strcpy") or
4039
insert.getTarget().hasGlobalName("strncpy")
4140
) and
4241
(
43-
append.getTarget().hasGlobalName("strcat") or
44-
append.getTarget().hasGlobalName("strncat")
42+
append.getTarget().hasGlobalOrStdName("strcat") or
43+
append.getTarget().hasGlobalOrStdName("strncat")
4544
) and
4645
malloc.getASuccessor+() = insert and
4746
insert.getArgument(1) = buffer.getAnAccess() and

cpp/ql/src/Critical/OverflowDestination.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import semmle.code.cpp.security.TaintTracking
2525
predicate sourceSized(FunctionCall fc, Expr src) {
2626
exists(string name |
2727
(name = "strncpy" or name = "strncat" or name = "memcpy" or name = "memmove") and
28-
fc.getTarget().hasGlobalName(name)
28+
fc.getTarget().hasGlobalOrStdName(name)
2929
) and
3030
exists(Expr dest, Expr size, Variable v |
3131
fc.getArgument(0) = dest and

cpp/ql/src/Critical/OverflowStatic.ql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,21 @@ predicate overflowOffsetInLoop(BufferAccess bufaccess, string msg) {
5858
}
5959

6060
predicate bufferAndSizeFunction(Function f, int buf, int size) {
61-
f.hasGlobalName("read") and buf = 1 and size = 2
61+
f.hasGlobalOrStdName("read") and buf = 1 and size = 2
6262
or
63-
f.hasGlobalName("fgets") and buf = 0 and size = 1
63+
f.hasGlobalOrStdName("fgets") and buf = 0 and size = 1
6464
or
65-
f.hasGlobalName("strncpy") and buf = 0 and size = 2
65+
f.hasGlobalOrStdName("strncpy") and buf = 0 and size = 2
6666
or
67-
f.hasGlobalName("strncat") and buf = 0 and size = 2
67+
f.hasGlobalOrStdName("strncat") and buf = 0 and size = 2
6868
or
69-
f.hasGlobalName("memcpy") and buf = 0 and size = 2
69+
f.hasGlobalOrStdName("memcpy") and buf = 0 and size = 2
7070
or
71-
f.hasGlobalName("memmove") and buf = 0 and size = 2
71+
f.hasGlobalOrStdName("memmove") and buf = 0 and size = 2
7272
or
73-
f.hasGlobalName("snprintf") and buf = 0 and size = 1
73+
f.hasGlobalOrStdName("snprintf") and buf = 0 and size = 1
7474
or
75-
f.hasGlobalName("vsnprintf") and buf = 0 and size = 1
75+
f.hasGlobalOrStdName("vsnprintf") and buf = 0 and size = 1
7676
}
7777

7878
class CallWithBufferSize extends FunctionCall {

cpp/ql/src/Critical/SizeCheck.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import cpp
1717
class Allocation extends FunctionCall {
1818
Allocation() {
1919
exists(string name |
20-
this.getTarget().hasGlobalName(name) and
20+
this.getTarget().hasGlobalOrStdName(name) and
2121
(name = "malloc" or name = "calloc" or name = "realloc")
2222
)
2323
}
2424

25-
private string getName() { this.getTarget().hasGlobalName(result) }
25+
private string getName() { this.getTarget().hasGlobalOrStdName(result) }
2626

2727
int getSize() {
2828
this.getName() = "malloc" and

cpp/ql/src/Critical/SizeCheck2.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import cpp
1717
class Allocation extends FunctionCall {
1818
Allocation() {
1919
exists(string name |
20-
this.getTarget().hasGlobalName(name) and
20+
this.getTarget().hasGlobalOrStdName(name) and
2121
(name = "malloc" or name = "calloc" or name = "realloc")
2222
)
2323
}
2424

25-
private string getName() { this.getTarget().hasGlobalName(result) }
25+
private string getName() { this.getTarget().hasGlobalOrStdName(result) }
2626

2727
int getSize() {
2828
this.getName() = "malloc" and

cpp/ql/src/Critical/UseAfterFree.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import semmle.code.cpp.controlflow.LocalScopeVariableReachability
1616
predicate isFreeExpr(Expr e, LocalScopeVariable v) {
1717
exists(VariableAccess va | va.getTarget() = v |
1818
exists(FunctionCall fc | fc = e |
19-
fc.getTarget().hasGlobalName("free") and
19+
fc.getTarget().hasGlobalOrStdName("free") and
2020
va = fc.getArgument(0)
2121
)
2222
or

cpp/ql/src/DefaultOptions.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Options extends string {
5959
predicate exits(Function f) {
6060
f.getAnAttribute().hasName("noreturn")
6161
or
62-
exists(string name | f.hasGlobalName(name) |
62+
exists(string name | f.hasGlobalOrStdName(name) |
6363
name = "exit" or
6464
name = "_exit" or
6565
name = "abort" or
@@ -91,7 +91,7 @@ class Options extends string {
9191
* By default holds only for `fgets`.
9292
*/
9393
predicate alwaysCheckReturnValue(Function f) {
94-
f.hasGlobalName("fgets") or
94+
f.hasGlobalOrStdName("fgets") or
9595
CustomOptions::alwaysCheckReturnValue(f) // old Options.qll
9696
}
9797

0 commit comments

Comments
 (0)