Skip to content

Commit da08c6e

Browse files
authored
Merge pull request github#5496 from MathiasVP/accept-model-getParameterSizeIndex-should-be-none
C++: Don't override getParameterSizeIndex in Accept
2 parents 1e6b539 + 585606a commit da08c6e

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

cpp/ql/src/semmle/code/cpp/models/implementations/Accept.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import semmle.code.cpp.models.interfaces.SideEffect
1515
private class Accept extends ArrayFunction, AliasFunction, TaintFunction, SideEffectFunction {
1616
Accept() { this.hasGlobalName(["accept", "accept4", "WSAAccept"]) }
1717

18-
override predicate hasArrayWithVariableSize(int bufParam, int countParam) {
19-
bufParam = 1 and countParam = 2
20-
}
18+
override predicate hasArrayWithUnknownSize(int bufParam) { bufParam = 1 }
2119

2220
override predicate hasArrayInput(int bufParam) { bufParam = 1 }
2321

@@ -46,8 +44,8 @@ private class Accept extends ArrayFunction, AliasFunction, TaintFunction, SideEf
4644
i = 1 and buffer = false
4745
}
4846

49-
override ParameterIndex getParameterSizeIndex(ParameterIndex i) { i = 1 and result = 2 }
50-
47+
// NOTE: The size parameter is a pointer to the size. So we can't implement `getParameterSizeIndex` for
48+
// this model.
5149
// NOTE: We implement thse two predicates as none because we can't model the low-level changes made to
5250
// the structure pointed to by the file-descriptor argument.
5351
override predicate hasOnlySpecificReadSideEffects() { none() }

cpp/ql/test/library-tests/dataflow/taint-tests/bsd.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ void test_accept() {
1919
int size = sizeof(sockaddr);
2020
int a = accept(s, &addr, &size);
2121

22-
sink(a); // $ ast=17:11 SPURIOUS: ast=18:12 MISSING: ir
23-
sink(addr); // $ ast MISSING: ir
22+
sink(a); // $ ast=17:11 ir SPURIOUS: ast=18:12
23+
sink(addr); // $ ast,ir
2424
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
void accept(int arg, char *buf, unsigned long* bufSize);
2+
3+
void testAccept(int socket1, int socket2)
4+
{
5+
char buffer[1024];
6+
accept(socket2, 0, 0);
7+
}

0 commit comments

Comments
 (0)