Skip to content

Commit 6b68cf6

Browse files
authored
Merge pull request #17076 from MathiasVP/add-missing-write-side-effect-to-remquo
C++: Add missing write side effect to `std::remquo`
2 parents 06a3bf8 + 91edf82 commit 6b68cf6

File tree

2 files changed

+22
-0
lines changed
  • cpp/ql
    • lib/semmle/code/cpp/models/implementations
    • test/query-tests/Security/CWE/CWE-457/semmle/tests

2 files changed

+22
-0
lines changed

cpp/ql/lib/semmle/code/cpp/models/implementations/StdMath.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ private class Remquo extends Function, SideEffectFunction {
5151
override predicate hasOnlySpecificReadSideEffects() { any() }
5252

5353
override predicate hasOnlySpecificWriteSideEffects() { any() }
54+
55+
override predicate hasSpecificWriteSideEffect(ParameterIndex i, boolean buffer, boolean mustWrite) {
56+
this.getParameter(i).getUnspecifiedType() instanceof PointerType and
57+
buffer = false and
58+
mustWrite = true
59+
}
5460
}
5561

5662
private class Fma extends Function, SideEffectFunction {
@@ -95,4 +101,8 @@ private class Nan extends Function, SideEffectFunction, AliasFunction {
95101
override predicate parameterNeverEscapes(int index) { index = 0 }
96102

97103
override predicate parameterEscapesOnlyViaReturn(int index) { none() }
104+
105+
override predicate hasSpecificReadSideEffect(ParameterIndex i, boolean buffer) {
106+
i = 0 and buffer = true
107+
}
98108
}

cpp/ql/test/query-tests/Security/CWE/CWE-457/semmle/tests/test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,3 +581,15 @@ void test46()
581581
*rP = nullptr;
582582
use(r);
583583
}
584+
585+
namespace std {
586+
float remquo(float, float, int*);
587+
}
588+
589+
void test47() {
590+
float x = 1.0f;
591+
float y = 2.0f;
592+
int quo;
593+
std::remquo(x, y, &quo);
594+
use(quo); // GOOD
595+
}

0 commit comments

Comments
 (0)