Skip to content

Commit 4018ed6

Browse files
author
Robert Marsh
committed
C++: respond to PR comments
1 parent 68c38ba commit 4018ed6

7 files changed

Lines changed: 9 additions & 12 deletions

File tree

cpp/ql/src/Critical/OverflowCalculated.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ predicate spaceProblem(FunctionCall append, string msg) {
3636
buffer.getAnAccess() = strlen.getStringExpr() and
3737
(
3838
insert.getTarget().hasGlobalOrStdName("strcpy") or
39-
insert.getTarget().hasGlobalName("strncpy")
39+
insert.getTarget().hasGlobalOrStdName("strncpy")
4040
) and
4141
(
4242
append.getTarget().hasGlobalOrStdName("strcat") or

cpp/ql/src/Critical/OverflowStatic.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ predicate overflowOffsetInLoop(BufferAccess bufaccess, string msg) {
5858
}
5959

6060
predicate bufferAndSizeFunction(Function f, int buf, int size) {
61-
f.hasGlobalOrStdName("read") and buf = 1 and size = 2
61+
f.hasGlobalName("read") and buf = 1 and size = 2
6262
or
6363
f.hasGlobalOrStdName("fgets") and buf = 0 and size = 1
6464
or

cpp/ql/src/Security/CWE/CWE-022/TaintedPath.ql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ class FileFunction extends FunctionWithWrappers {
3434
nme.matches("CreateFile%")
3535
)
3636
or
37-
exists(string nme | this.hasStdName(nme) |
38-
nme = "fopen" or
39-
nme = "open"
40-
)
37+
this.hasStdName("fopen")
4138
or
4239
// on any of the fstream classes, or filebuf
4340
exists(string nme | this.getDeclaringType().hasStdName(nme) |

cpp/ql/src/Security/CWE/CWE-121/UnterminatedVarargsCall.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class VarargsFunction extends Function {
6666
}
6767

6868
predicate isWhitelisted() {
69-
this.hasGlobalOrStdName("open") or
69+
this.hasGlobalName("open") or
7070
this.hasGlobalName("fcntl") or
7171
this.hasGlobalName("ptrace")
7272
}

cpp/ql/src/semmle/code/cpp/commons/File.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ predicate fcloseCall(FunctionCall fc, Expr closed) {
2626
f.hasGlobalOrStdName("fclose") and
2727
closed = fc.getArgument(0)
2828
or
29-
f.hasGlobalOrStdName("close") and
29+
f.hasGlobalName("close") and
3030
closed = fc.getArgument(0)
3131
or
32-
f.hasGlobalOrStdName("_close") and
32+
f.hasGlobalName("_close") and
3333
closed = fc.getArgument(0)
3434
or
3535
f.hasGlobalOrStdName("CloseHandle") and

cpp/ql/src/semmle/code/cpp/security/Security.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ class SecurityOptions extends string {
7373
functionCall.getTarget().hasGlobalOrStdName(fname) and
7474
exists(functionCall.getArgument(arg)) and
7575
(
76-
fname = "read" and arg = 1
77-
or
7876
fname = "fread" and arg = 0
7977
or
8078
fname = "fgets" and arg = 0
@@ -91,6 +89,8 @@ class SecurityOptions extends string {
9189
functionCall.getTarget().hasGlobalName(fname) and
9290
exists(functionCall.getArgument(arg)) and
9391
(
92+
fname = "read" and arg = 1
93+
or
9494
fname = "getaddrinfo" and arg = 3
9595
or
9696
fname = "recv" and arg = 1

cpp/ql/src/semmle/code/cpp/security/TaintTracking.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ private predicate copyValueBetweenArguments(Function f, int sourceArg, int destA
459459
or
460460
f.hasGlobalName("inet_pton") and sourceArg = 1 and destArg = 2
461461
or
462-
f.hasGlobalName("strftime") and sourceArg in [2 .. maxArgIndex(f)] and destArg = 0
462+
f.hasGlobalOrStdName("strftime") and sourceArg in [2 .. maxArgIndex(f)] and destArg = 0
463463
or
464464
exists(FormattingFunction ff | ff = f |
465465
sourceArg in [ff.getFormatParameterIndex() .. maxArgIndex(f)] and

0 commit comments

Comments
 (0)