Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/scripts/upgrade-codeql-depend…
Browse files Browse the repository at this point in the history
…encies/urllib3-2.0.6
  • Loading branch information
lcartey authored Oct 5, 2023
2 parents 805dc57 + e786157 commit df3710e
Show file tree
Hide file tree
Showing 326 changed files with 752 additions and 519 deletions.
8 changes: 5 additions & 3 deletions c/cert/src/codeql-pack.lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
lockVersion: 1.0.0
dependencies:
codeql/cpp-all:
version: 0.6.1
version: 0.7.4
codeql/ssa:
version: 0.0.14
version: 0.0.19
codeql/tutorial:
version: 0.0.7
version: 0.0.12
codeql/util:
version: 0.0.12
compiled: false
2 changes: 1 addition & 1 deletion c/cert/src/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ suites: codeql-suites
license: MIT
dependencies:
codeql/common-c-coding-standards: '*'
codeql/cpp-all: 0.6.1
codeql/cpp-all: 0.7.4
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,42 @@
* external/cert/obligation/rule
*/

import cpp
import codingstandards.c.cert
import codingstandards.c.OutOfBounds

from
OOB::BufferAccess ba, Expr bufferArg, Expr sizeArg, OOB::PointerToObjectSource bufferSource,
string message
where
not isExcluded(ba, OutOfBoundsPackage::doNotFormOutOfBoundsPointersOrArraySubscriptsQuery()) and
// exclude loops
not exists(Loop loop | loop.getStmt().getChildStmt*() = ba.getEnclosingStmt()) and
// exclude size arguments that are of type ssize_t
not sizeArg.getAChild*().(VariableAccess).getTarget().getType() instanceof Ssize_t and
// exclude size arguments that are assigned the result of a function call e.g. ftell
not sizeArg.getAChild*().(VariableAccess).getTarget().getAnAssignedValue() instanceof FunctionCall and
// exclude field or array accesses for the size arguments
not sizeArg.getAChild*() instanceof FieldAccess and
not sizeArg.getAChild*() instanceof ArrayExpr and
(
exists(int sizeArgValue, int bufferArgSize |
OOB::isSizeArgGreaterThanBufferSize(bufferArg, sizeArg, bufferSource, bufferArgSize, sizeArgValue, ba) and
message =
"Buffer accesses offset " + sizeArgValue +
" which is greater than the fixed size " + bufferArgSize + " of the $@."
)
or
exists(int sizeArgUpperBound, int sizeMult, int bufferArgSize |
OOB::isSizeArgNotCheckedLessThanFixedBufferSize(bufferArg, sizeArg, bufferSource,
bufferArgSize, ba, sizeArgUpperBound, sizeMult) and
message =
"Buffer may access up to offset " + sizeArgUpperBound + "*" + sizeMult +
" which is greater than the fixed size " + bufferArgSize + " of the $@."
)
or
OOB::isSizeArgNotCheckedGreaterThanZero(bufferArg, sizeArg, bufferSource, ba) and
message = "Buffer access may be to a negative index in the buffer."
)
select ba, message, bufferSource, "buffer"
import cpp
import codingstandards.c.cert
import codingstandards.c.OutOfBounds

from
OOB::BufferAccess ba, Expr bufferArg, Expr sizeArg, OOB::PointerToObjectSource bufferSource,
string message
where
not isExcluded(ba, OutOfBoundsPackage::doNotFormOutOfBoundsPointersOrArraySubscriptsQuery()) and
// exclude loops
not exists(Loop loop | loop.getStmt().getChildStmt*() = ba.getEnclosingStmt()) and
// exclude size arguments that are of type ssize_t
not sizeArg.getAChild*().(VariableAccess).getTarget().getType() instanceof Ssize_t and
// exclude size arguments that are assigned the result of a function call e.g. ftell
not sizeArg.getAChild*().(VariableAccess).getTarget().getAnAssignedValue() instanceof FunctionCall and
// exclude field or array accesses for the size arguments
not sizeArg.getAChild*() instanceof FieldAccess and
not sizeArg.getAChild*() instanceof ArrayExpr and
(
exists(int sizeArgValue, int bufferArgSize |
OOB::isSizeArgGreaterThanBufferSize(bufferArg, sizeArg, bufferSource, bufferArgSize,
sizeArgValue, ba) and
message =
"Buffer accesses offset " + sizeArgValue + " which is greater than the fixed size " +
bufferArgSize + " of the $@."
)
or
exists(int sizeArgUpperBound, int sizeMult, int bufferArgSize |
OOB::isSizeArgNotCheckedLessThanFixedBufferSize(bufferArg, sizeArg, bufferSource,
bufferArgSize, ba, sizeArgUpperBound, sizeMult) and
message =
"Buffer may access up to offset " + sizeArgUpperBound + "*" + sizeMult +
" which is greater than the fixed size " + bufferArgSize + " of the $@."
)
or
OOB::isSizeArgNotCheckedGreaterThanZero(bufferArg, sizeArg, bufferSource, ba) and
message = "Buffer access may be to a negative index in the buffer."
)
select ba, message, bufferSource, "buffer"
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.donotuserelationaloperatorswithdifferingarrays.DoNotUseRelationalOperatorsWithDifferingArrays

class DoNotRelatePointersThatDoNotReferToTheSameArrayQuery extends DoNotUseRelationalOperatorsWithDifferingArraysSharedQuery {
class DoNotRelatePointersThatDoNotReferToTheSameArrayQuery extends DoNotUseRelationalOperatorsWithDifferingArraysSharedQuery
{
DoNotRelatePointersThatDoNotReferToTheSameArrayQuery() {
this = Memory2Package::doNotRelatePointersThatDoNotReferToTheSameArrayQuery()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.donotsubtractpointersaddressingdifferentarrays.DoNotSubtractPointersAddressingDifferentArrays

class DoNotSubtractPointersThatDoNotReferToTheSameArrayQuery extends DoNotSubtractPointersAddressingDifferentArraysSharedQuery {
class DoNotSubtractPointersThatDoNotReferToTheSameArrayQuery extends DoNotSubtractPointersAddressingDifferentArraysSharedQuery
{
DoNotSubtractPointersThatDoNotReferToTheSameArrayQuery() {
this = Memory2Package::doNotSubtractPointersThatDoNotReferToTheSameArrayQuery()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ from
where
not isExcluded(fc, OutOfBoundsPackage::libraryFunctionArgumentOutOfBoundsQuery()) and
OOB::problems(fc, message, bufferArg, bufferArgStr, sizeOrOtherBufferArg, otherStr)
select fc, message, bufferArg, bufferArgStr, sizeOrOtherBufferArg, otherStr
select fc, message, bufferArg, bufferArgStr, sizeOrOtherBufferArg, otherStr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.donotallowamutextogooutofscopewhilelocked.DoNotAllowAMutexToGoOutOfScopeWhileLocked

class DoNotAllowAMutexToGoOutOfScopeWhileLockedQuery extends DoNotAllowAMutexToGoOutOfScopeWhileLockedSharedQuery {
class DoNotAllowAMutexToGoOutOfScopeWhileLockedQuery extends DoNotAllowAMutexToGoOutOfScopeWhileLockedSharedQuery
{
DoNotAllowAMutexToGoOutOfScopeWhileLockedQuery() {
this = Concurrency3Package::doNotAllowAMutexToGoOutOfScopeWhileLockedQuery()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ where
"setlocale", "atomic_init", "ATOMIC_VAR_INIT", "tmpnam", "mbrtoc16", "c16rtomb", "mbrtoc32",
"c32rtomb"
]
select node,
"Concurrent call to non-reeantrant function $@.", node.(FunctionCall).getTarget(), node.(FunctionCall).getTarget().getName()
select node, "Concurrent call to non-reeantrant function $@.", node.(FunctionCall).getTarget(),
node.(FunctionCall).getTarget().getName()
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.preventdeadlockbylockinginpredefinedorder.PreventDeadlockByLockingInPredefinedOrder

class DeadlockByLockingInPredefinedOrderQuery extends PreventDeadlockByLockingInPredefinedOrderSharedQuery {
class DeadlockByLockingInPredefinedOrderQuery extends PreventDeadlockByLockingInPredefinedOrderSharedQuery
{
DeadlockByLockingInPredefinedOrderQuery() {
this = Concurrency2Package::deadlockByLockingInPredefinedOrderQuery()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ where
not isExcluded(fc, Concurrency1Package::doNotCallSignalInMultithreadedProgramQuery()) and
fc.getTarget().getName() = "signal" and
exists(ThreadedFunction f)
select fc,
"Call to `signal()` in multithreaded programs."
select fc, "Call to `signal()` in multithreaded programs."
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.preservesafetywhenusingconditionvariables.PreserveSafetyWhenUsingConditionVariables

class PreserveSafetyWhenUsingConditionVariablesQuery extends PreserveSafetyWhenUsingConditionVariablesSharedQuery {
class PreserveSafetyWhenUsingConditionVariablesQuery extends PreserveSafetyWhenUsingConditionVariablesSharedQuery
{
PreserveSafetyWhenUsingConditionVariablesQuery() {
this = Concurrency3Package::preserveSafetyWhenUsingConditionVariablesQuery()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
* external/cert/obligation/rule
*/

import cpp
import codingstandards.c.cert
import codingstandards.cpp.Concurrency

import cpp
import codingstandards.c.cert
import codingstandards.cpp.Concurrency

from AtomicCompareExchange ace
where
not isExcluded(ace, Concurrency3Package::wrapFunctionsThatCanFailSpuriouslyInLoopQuery()) and
(
forex(StmtParent sp | sp = ace.getStmt() | not sp.(Stmt).getParentStmt*() instanceof Loop) or
forex(Expr e | e = ace.getExpr() | not e.getEnclosingStmt().getParentStmt*()
instanceof Loop)
)
select ace, "Function that can spuriously fail not wrapped in a loop."

from AtomicCompareExchange ace
where
not isExcluded(ace, Concurrency3Package::wrapFunctionsThatCanFailSpuriouslyInLoopQuery()) and
(
forex(StmtParent sp | sp = ace.getStmt() | not sp.(Stmt).getParentStmt*() instanceof Loop)
or
forex(Expr e | e = ace.getExpr() | not e.getEnclosingStmt().getParentStmt*() instanceof Loop)
)
select ace, "Function that can spuriously fail not wrapped in a loop."
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.donotcopyaddressofautostorageobjecttootherobject.DoNotCopyAddressOfAutoStorageObjectToOtherObject

class AppropriateStorageDurationsStackAdressEscapeQuery extends DoNotCopyAddressOfAutoStorageObjectToOtherObjectSharedQuery {
class AppropriateStorageDurationsStackAdressEscapeQuery extends DoNotCopyAddressOfAutoStorageObjectToOtherObjectSharedQuery
{
AppropriateStorageDurationsStackAdressEscapeQuery() {
this = Declarations8Package::appropriateStorageDurationsStackAdressEscapeQuery()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.informationleakageacrossboundaries.InformationLeakageAcrossBoundaries

class InformationLeakageAcrossTrustBoundariesCQuery extends InformationLeakageAcrossBoundariesSharedQuery {
class InformationLeakageAcrossTrustBoundariesCQuery extends InformationLeakageAcrossBoundariesSharedQuery
{
InformationLeakageAcrossTrustBoundariesCQuery() {
this = Declarations7Package::informationLeakageAcrossTrustBoundariesCQuery()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.invalidatedenvstringpointerswarn.InvalidatedEnvStringPointersWarn

class DoNotStorePointersReturnedByEnvironmentFunWarnQuery extends InvalidatedEnvStringPointersWarnSharedQuery {
class DoNotStorePointersReturnedByEnvironmentFunWarnQuery extends InvalidatedEnvStringPointersWarnSharedQuery
{
DoNotStorePointersReturnedByEnvironmentFunWarnQuery() {
this = Contracts2Package::doNotStorePointersReturnedByEnvironmentFunWarnQuery()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import codingstandards.c.Errno
import codingstandards.c.Signal
import semmle.code.cpp.controlflow.Guards


/**
* A check on `signal` call return value
* `if (signal(SIGINT, handler) == SIG_ERR)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class DefaultAlignedPointerExpr extends UnconvertedCastFromNonVoidPointerExpr, E
* to exclude an `DefaultAlignedPointerAccessExpr` as a source if a preceding source
* defined by this configuration provides more accurate alignment information.
*/
class AllocationOrAddressOfExprToUnconvertedCastFromNonVoidPointerExprConfig extends DataFlow2::Configuration {
class AllocationOrAddressOfExprToUnconvertedCastFromNonVoidPointerExprConfig extends DataFlow2::Configuration
{
AllocationOrAddressOfExprToUnconvertedCastFromNonVoidPointerExprConfig() {
this = "AllocationOrAddressOfExprToUnconvertedCastFromNonVoidPointerExprConfig"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ Type compatibleTypes(Type type) {
(
type.stripType() instanceof Struct and
type.getUnspecifiedType() = result.getUnspecifiedType() and
not type.getName() = "struct <unnamed>" and
not result.getName() = "struct <unnamed>"
not type.(Struct).isAnonymous() and
not result.(Struct).isAnonymous()
or
not type.stripType() instanceof Struct and
(
Expand Down
4 changes: 1 addition & 3 deletions c/cert/src/rules/EXP42-C/DoNotComparePaddingData.ql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ import codingstandards.c.cert
import codingstandards.cpp.rules.memcmpusedtocomparepaddingdata.MemcmpUsedToComparePaddingData

class DoNotComparePaddingDataQuery extends MemcmpUsedToComparePaddingDataSharedQuery {
DoNotComparePaddingDataQuery() {
this = Memory2Package::doNotComparePaddingDataQuery()
}
DoNotComparePaddingDataQuery() { this = Memory2Package::doNotComparePaddingDataQuery() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module TaintedPathConfiguration implements DataFlow::ConfigSig {
}
}

module TaintedPath = TaintTracking::Make<TaintedPathConfiguration>;
module TaintedPath = TaintTracking::Global<TaintedPathConfiguration>;

from
FileFunction fileFunction, Expr taintedArg, FlowSource taintSource,
Expand All @@ -98,7 +98,7 @@ where
not isExcluded(taintedArg, IO3Package::doNotPerformFileOperationsOnDevicesQuery()) and
taintedArg = sinkNode.getNode().asIndirectArgument() and
fileFunction.outermostWrapperFunctionCall(taintedArg, callChain) and
TaintedPath::hasFlowPath(sourceNode, sinkNode) and
TaintedPath::flowPath(sourceNode, sinkNode) and
taintSource = sourceNode.getNode()
select taintedArg, sourceNode, sinkNode,
"This argument to a file access function is derived from $@ and then passed to " + callChain + ".",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.iofstreammissingpositioning.IOFstreamMissingPositioning

class DoNotAlternatelyIOFromAStreamWithoutPositioningQuery extends IOFstreamMissingPositioningSharedQuery {
class DoNotAlternatelyIOFromAStreamWithoutPositioningQuery extends IOFstreamMissingPositioningSharedQuery
{
DoNotAlternatelyIOFromAStreamWithoutPositioningQuery() {
this = IO1Package::doNotAlternatelyIOFromAStreamWithoutPositioningQuery()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.closefilehandlewhennolongerneededshared.CloseFileHandleWhenNoLongerNeededShared

class CloseFilesWhenTheyAreNoLongerNeededQuery extends CloseFileHandleWhenNoLongerNeededSharedSharedQuery {
class CloseFilesWhenTheyAreNoLongerNeededQuery extends CloseFileHandleWhenNoLongerNeededSharedSharedQuery
{
CloseFilesWhenTheyAreNoLongerNeededQuery() {
this = IO1Package::closeFilesWhenTheyAreNoLongerNeededQuery()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.onlyfreememoryallocateddynamicallyshared.OnlyFreeMemoryAllocatedDynamicallyShared

class OnlyFreeMemoryAllocatedDynamicallyCertQuery extends OnlyFreeMemoryAllocatedDynamicallySharedSharedQuery {
class OnlyFreeMemoryAllocatedDynamicallyCertQuery extends OnlyFreeMemoryAllocatedDynamicallySharedSharedQuery
{
OnlyFreeMemoryAllocatedDynamicallyCertQuery() {
this = Memory2Package::onlyFreeMemoryAllocatedDynamicallyCertQuery()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.donotuserandforgeneratingpseudorandomnumbers.DoNotUseRandForGeneratingPseudorandomNumbers

class RandUsedForGeneratingPseudorandomNumbersQuery extends DoNotUseRandForGeneratingPseudorandomNumbersSharedQuery {
class RandUsedForGeneratingPseudorandomNumbersQuery extends DoNotUseRandForGeneratingPseudorandomNumbersSharedQuery
{
RandUsedForGeneratingPseudorandomNumbersQuery() {
this = MiscPackage::randUsedForGeneratingPseudorandomNumbersQuery()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,22 @@ import codingstandards.c.cert

/** Defines a class that models function calls to srandom() */
class SRandomCall extends FunctionCall {
SRandomCall(){
getTarget().hasGlobalOrStdName("srandom")
}
SRandomCall() { getTarget().hasGlobalOrStdName("srandom") }

/** Holds if the call is not obviously trivial. */
predicate isTrivial(){
getArgument(0) instanceof Literal
}
predicate isTrivial() { getArgument(0) instanceof Literal }
}

from FunctionCall fc
where
not isExcluded(fc, MiscPackage::properlySeedPseudorandomNumberGeneratorsQuery()) and

// find all calls to random()
fc.getTarget().hasGlobalOrStdName("random") and

// find all calls to random()
fc.getTarget().hasGlobalOrStdName("random") and
// where there isn't a call to srandom that comes before it that is
// non-trivial
not exists(SRandomCall sr |
// normally we would want to do this in reverse --- but srandom() is
// not pure and the order does not matter.
// normally we would want to do this in reverse --- but srandom() is
// not pure and the order does not matter.
sr.getASuccessor*() = fc and not sr.isTrivial()
)


select fc, "Call to `random()` without a valid call to `srandom()`."
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.rules.nonvoidfunctiondoesnotreturn.NonVoidFunctionDoesNotReturn

class ControlFlowReachesTheEndOfANonVoidFunctionQuery extends NonVoidFunctionDoesNotReturnSharedQuery {
class ControlFlowReachesTheEndOfANonVoidFunctionQuery extends NonVoidFunctionDoesNotReturnSharedQuery
{
ControlFlowReachesTheEndOfANonVoidFunctionQuery() {
this = MiscPackage::controlFlowReachesTheEndOfANonVoidFunctionQuery()
}
Expand Down
8 changes: 5 additions & 3 deletions c/cert/test/codeql-pack.lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
lockVersion: 1.0.0
dependencies:
codeql/cpp-all:
version: 0.6.1
version: 0.7.4
codeql/ssa:
version: 0.0.14
version: 0.0.19
codeql/tutorial:
version: 0.0.7
version: 0.0.12
codeql/util:
version: 0.0.12
compiled: false
Loading

0 comments on commit df3710e

Please sign in to comment.