diff --git a/cpp/ql/src/semmle/code/cpp/dataflow/EscapesTree.qll b/cpp/ql/src/semmle/code/cpp/dataflow/EscapesTree.qll index 4f9474e2efc6..911b796077b1 100644 --- a/cpp/ql/src/semmle/code/cpp/dataflow/EscapesTree.qll +++ b/cpp/ql/src/semmle/code/cpp/dataflow/EscapesTree.qll @@ -198,6 +198,10 @@ private predicate valueMayEscapeMutablyAt(Expr e) { or t instanceof ReferenceType and not t.(ReferenceType).getBaseType().isConst() + or + // If the address has been cast to an integral type, conservatively assume that it may eventually be cast back to a + // pointer to non-const type. + t instanceof IntegralType ) } diff --git a/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.c b/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.c index 1ab2983645e8..f1d086482242 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.c +++ b/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.c @@ -342,3 +342,25 @@ int nan2(double x) { } } } + +struct info_t { + int id; + unsigned long long value; +}; + +int command(void* p, unsigned int s); + +int callCommand(void) +{ + struct info_t info; + unsigned int tmp = 0; + + info.id = 1; + info.value = (unsigned long long)& tmp; + if (command(&info, sizeof(info))) { + return 0; + } + if (tmp == 1) // tmp could have been modified by the call. + return 1; + return 0; +} \ No newline at end of file