Skip to content
Draft

Next #1146

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
1c82682
Update expected test results after frontend update
jketema Mar 6, 2025
ce14612
Merge pull request #865 from jketema/frontend-update
jketema Jun 4, 2025
d6b55ca
Merge branch 'main' into next
jketema Jun 4, 2025
f07f569
Update MISRA queries and tests after merging location tables
jketema Jun 27, 2025
3b4a91c
Merge pull request #915 from jketema/loc-table-merge
jketema Jun 30, 2025
67adebb
C++: accept new test results after QL changes
IdrissRio Jun 30, 2025
60c2e05
Merge pull request #916 from IdrissRio/next
jketema Jul 1, 2025
740bcd0
Merge remote-tracking branch 'upstream/main' into next
jketema Jul 2, 2025
2089bcd
Comvert ARR37-C to use the new dataflow library
jketema Jul 7, 2025
cf1b625
Conver ARR39-C to the new dataflow library
jketema Jul 7, 2025
8d73f3b
Convert ERR30-C to use the new dataflow library
jketema Jul 7, 2025
7a1577e
Convert FIO45-C to use the new dataflow library
jketema Jul 7, 2025
c5c6c58
Convert EXP36-C to the new datafow library
jketema Jul 7, 2025
8fdea49
Convert MSC33-C to the new dataflow library
jketema Jul 7, 2025
3289621
Convert MSC51-CPP to the new dataflow library
jketema Jul 7, 2025
d20cd3a
Convert CTR56-CPP to the new dataflow library
jketema Jul 7, 2025
77e8e0e
Convert EXP51-CPP ot use the new dataflow library
jketema Jul 7, 2025
57b6091
Conver M3-9-3 to use the new dataflow library
jketema Jul 7, 2025
357ee08
Convert A9-3-1 to use the new dataflow library
jketema Jul 7, 2025
30114c5
Convert A27-0-4 to use the new dataflow library
jketema Jul 7, 2025
d313bf2
Convert A5-0-4 to use the new dataflow library
jketema Jul 7, 2025
500e96a
Merge pull request #920 from jketema/jketema/dataflow
jketema Jul 7, 2025
8529fbb
Update expected test results for MSC33-C
jketema Jul 7, 2025
363faea
Merge pull request #921 from jketema/jketema/dataflow
jketema Jul 7, 2025
012ac3d
Create temporary copies of parts of the concurrency library
jketema Jul 7, 2025
22b8860
Convert CON30-C to use the new dataflow library
jketema Jul 7, 2025
0a846c7
Convert CON34-C to the new dataflow library
jketema Jul 8, 2025
1c1f3fb
Move queries not depending on dataflow over to `ConcurrencyNew`
jketema Jul 8, 2025
3ba33c0
Convert UseOnlyArrayIndexingForPointerArithmetic to use the new dataf…
jketema Jul 8, 2025
e2d44a6
Convert StringNumberConversionMissingErrorCheck to use the new datafl…
jketema Jul 8, 2025
5ee401c
Convert FgetsErrorManagement to use the new dataflow library
jketema Jul 8, 2025
96b3137
Convert RULE-22-3 to use the new dataflow library
jketema Jul 8, 2025
0170b58
Convert RULE-22-4 to use the new dataflow library
jketema Jul 8, 2025
8080952
Convert A7-5-1 to use the new dataflow library
jketema Jul 8, 2025
c962dbe
Convert DoNotSubtractPointersAddressingDifferentArrays to use new dat…
jketema Jul 8, 2025
8c05d42
Remove unused dataflow import from IOFstreamMissingPositioning
jketema Jul 8, 2025
b18c7b4
Convert DanglingCaptureWhenReturningLambdaObject to use new dataflow …
jketema Jul 8, 2025
f8eaa1e
Merge pull request #922 from jketema/jketema/dataflow
jketema Jul 8, 2025
8ee97ba
Revert "Convert DanglingCaptureWhenReturningLambdaObject to use new d…
jketema Jul 8, 2025
e08c0f7
Merge pull request #923 from jketema/jketema/dataflow
jketema Jul 8, 2025
ebad011
Merge remote-tracking branch 'upstream/main' into next
jketema Jul 10, 2025
405c43e
Fix FIO40-C regression after incorrectly solving a merge conflict
jketema Jul 10, 2025
7c7d6f6
Conver ARR32-C to use the new dataflow library
jketema Jul 10, 2025
1d30fd5
Convert DCL30-C to the new dataflow library
jketema Jul 10, 2025
43c96a7
Convert ERR32-C to use the new dataflow library
jketema Jul 10, 2025
15b9143
Convert ERR33-C to use the new dataflow library
jketema Jul 10, 2025
9ca601a
Convert EXP37-C to the new dataflow library
jketema Jul 10, 2025
1309e18
Convert EXP40-C to the new dataflow library
jketema Jul 10, 2025
25571ec
Convert FIO44-C to the new dataflow library
jketema Jul 10, 2025
3cb8899
Convert MEM35-C to the new dataflow library
jketema Jul 10, 2025
f8daf8c
Convert MEM36-C to the new dataflow library
jketema Jul 10, 2025
8924137
Convert SIG30-C to the new dataflow library
jketema Jul 10, 2025
6865078
Convert SIG35-C to the new dataflow library
jketema Jul 10, 2025
0910b4f
Convert Signal library to the new data flow library
jketema Jul 10, 2025
7b5eba0
Convert RULE-13-2 to the new dataflow library
jketema Jul 11, 2025
dc76e3c
Convert RULE-21-14 to the new dataflow library
jketema Jul 11, 2025
d65bc91
Convert RULE-22-7 to the new dataflow library
jketema Jul 11, 2025
fc2ab4b
Convert A13-1-3 to the new dataflow library
jketema Jul 11, 2025
3dae0a6
Convert A13-2-1 to the new dataflow library
jketema Jul 11, 2025
2cc7388
Convert A15-1-3 to the new dataflow library
jketema Jul 11, 2025
88ff741
Address review comment
jketema Jul 11, 2025
1c222ae
Merge pull request #927 from jketema/jketema/dataflow-2
jketema Jul 11, 2025
0e8f03e
Merge remote-tracking branch 'upstream/main' into next
jketema Jul 11, 2025
6603c25
C++: Accept path changes caused by codeql#20040.
MathiasVP Jul 14, 2025
bd434ed
Merge pull request #929 from MathiasVP/accept-paht-changes-after-20040
jketema Jul 14, 2025
c159604
Convert RULE-17-5 to the new dataflow library
jketema Jul 15, 2025
36eb3b3
Convert A15-2-2 to use the new dataflow library
jketema Jul 15, 2025
ba9ebc6
Convert A18-9-4 to use the new dataflow library
jketema Jul 15, 2025
f4d7e9f
Convert A20-8-4 to use the new dataflow library
jketema Jul 15, 2025
7b37153
Merge pull request #930 from jketema/dataflow-3
jketema Jul 15, 2025
2aceba8
Convert A5-1-7 to use the new dataflow library
jketema Jul 15, 2025
c989403
Convert A8-4-12 to use the new dataflow library
jketema Jul 15, 2025
abc8797
Convert CTR52-CPP to the new dataflow library
jketema Jul 15, 2025
86f055d
Convert CTR53-CPP to the new dataflow library
jketema Jul 15, 2025
a7924d5
Merge pull request #934 from jketema/dataflow-4
jketema Jul 16, 2025
bfdf262
C++: Block flow into thread-specific storage creating functions (i.e.…
MathiasVP Jul 25, 2025
086a4ed
C++: Accept test changes to another query.
MathiasVP Jul 25, 2025
dfff976
Merge pull request #936 from MathiasVP/better-global-variable-flow-fo…
jketema Aug 11, 2025
3a2b007
Merge remote-tracking branch 'upstream/main' into next
jketema Aug 15, 2025
3287062
Merge remote-tracking branch 'upstream/main' into next
jketema Aug 19, 2025
f0d4694
Convert `ThrowingOperatorNewReturnsNull` to the new dataflow library
jketema Aug 15, 2025
b6a4ae9
Convert `PredicateFunctionObjectsShouldNotBeMutable` to the new dataf…
jketema Aug 15, 2025
ca1667f
Remove redundant dataflow import
jketema Aug 15, 2025
e643526
Convert `OnlyFreeMemoryAllocatedDynamicallyShared` to the new dataflo…
jketema Aug 15, 2025
0f50470
Convert `InvalidatedEnvStringPointers` to the new dataflow library
jketema Aug 15, 2025
493a4c1
Convert `FunctionErroneousReturnValueNotTested` to the new dataflow l…
jketema Aug 18, 2025
8a672b1
Update `DoNotPassAliasedPointerToRestrictQualifiedParamShared` to the…
jketema Aug 18, 2025
3bfaf5b
Convert M9-3-1 to the new dataflow library
jketema Aug 19, 2025
56cc455
Convert A8-4-9 to the new dataflow library
jketema Aug 19, 2025
6384dbd
Conver A8-4-11 to the new dataflow library
jketema Aug 19, 2025
113c121
Convert STR31-C to the new dataflow library
jketema Aug 19, 2025
f265690
Convert `FileStreams.qll` to the new dataflow library
jketema Aug 19, 2025
146d85a
Convert `DoNotAccessAClosedFile` to the new dataflow library
jketema Aug 19, 2025
4d16b3b
Update `OwnedPointerValueStoredInUnrelatedSmartPointer` to the new da…
jketema Aug 21, 2025
3b05adc
Update `MovedFromObjectsUnspecifiedState` to the new dataflow library
jketema Aug 21, 2025
ab5a471
Update `DoNotUseRelationalOperatorsWithDifferingArrays` to the new da…
jketema Aug 21, 2025
590cd5a
Convert `DanglingCaptureWhenReturningLambdaObject` to the new dataflo…
jketema Aug 21, 2025
42838bf
Update `DanglingCaptureWhenMovingLambdaObject` to the new dataflow li…
jketema Aug 21, 2025
a11320c
Update `ConstLikeReturnValue` to the new dataflow library
jketema Aug 21, 2025
99b45ad
Remove redundant dataflow import
jketema Aug 21, 2025
5e701b5
Convert `BasicStringMayNotBeNullTerminated` to the new dataflow library
jketema Aug 21, 2025
e293289
Merge pull request #949 from jketema/dataflow-new
jketema Aug 22, 2025
1f68a2f
C++: Fix up queries after github/codeql#20485.
MathiasVP Sep 18, 2025
68be4b0
Merge pull request #958 from MathiasVP/fixup-queries-after-shared-guards
jketema Oct 2, 2025
ff90ac7
C++: Fix queries I forgot after merging github/codeql#20485.
MathiasVP Oct 2, 2025
7ee21c4
Merge pull request #959 from MathiasVP/fix-more-queries-after-shared-…
jketema Oct 2, 2025
6d4dd9d
C++: Accept line number changes in .expected file.
MathiasVP Oct 2, 2025
114bc1e
Merge pull request #960 from MathiasVP/fix-more-queries-after-shared-…
jketema Oct 2, 2025
4d5680a
Merge remote-tracking branch 'upstream/main' into next
jketema Nov 8, 2025
c605527
Update expected test results
jketema Nov 8, 2025
11d0d15
Update expected test results after frontend update
jketema Nov 27, 2025
9134f4a
Merge pull request #988 from jketema/jketema/frontend-update
jketema Jan 6, 2026
421866e
Floating point decimal support has been removed from CodeQL
jketema Jan 6, 2026
17b5cef
Fix test formatting
jketema Jan 8, 2026
054ebcf
Merge pull request #1014 from jketema/jketema/rm-decimal
jketema Jan 14, 2026
141d5be
C++: Accept test changes after github/codeql#21313.
MathiasVP Feb 11, 2026
d6955b0
C++: Fix Copilot comments.
MathiasVP Feb 11, 2026
cda7e81
Merge pull request #1036 from MathiasVP/accept-changes-after-21313
jketema Feb 16, 2026
115639d
Revert "C++: Accept test changes after github/codeql#21313."
paldepind Feb 16, 2026
2da1be3
Update test expectations after switch to SoftFloat library in the ext…
jketema Feb 17, 2026
09d1e3a
Merge pull request #1041 from paldepind/revert-accept-changes-after-2…
jketema Feb 20, 2026
3bc45b8
Merge pull request #1042 from jketema/jketema/softfloat
jketema Feb 23, 2026
b883139
Revert "Merge pull request #1042 from jketema/jketema/softfloat"
jketema Feb 24, 2026
330fc79
Merge pull request #1055 from jketema/jketema/softfloat-revert
jketema Feb 24, 2026
0be4a82
Merge branch 'main' into next
jketema Mar 30, 2026
a7b10a1
Update expected test results
jketema Mar 30, 2026
bfc504c
Reapply "Merge pull request #1042 from jketema/jketema/softfloat"
jketema Apr 24, 2026
863046b
Merge pull request #1118 from jketema/softfloat
jketema Apr 28, 2026
08b109d
Update type alias class names
jketema May 18, 2026
9c6f08c
Merge pull request #1131 from jketema/jketema/alias-template
jketema May 19, 2026
da5f262
Update expected test results
jketema May 19, 2026
4349da6
Update references to deprecated classes
jketema May 19, 2026
99a5245
Update references to deprecated classes
jketema May 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import cpp
import codingstandards.c.cert
import codingstandards.cpp.Overflow
import semmle.code.cpp.dataflow.TaintTracking
import semmle.code.cpp.dataflow.new.TaintTracking

/**
* Gets the maximum size (in bytes) a variable-length array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import cpp
import codingstandards.c.cert
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow
import NonArrayPointerToArrayIndexingExprFlow::PathGraph

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import cpp
import codingstandards.c.cert
import codingstandards.cpp.types.Pointers
import semmle.code.cpp.dataflow.TaintTracking
import semmle.code.cpp.dataflow.new.TaintTracking
import ScaledIntegerPointerArithmeticFlow::PathGraph

/**
Expand Down Expand Up @@ -61,9 +61,11 @@ class ScaledIntegerExpr extends Expr {
ScaledIntegerExpr() {
not this.getParent*() instanceof ArrayCountOfExpr and
(
this.(SizeofExprOperator).getExprOperand().getType().getSize() > 1
exists(this.getValue()) and
this.getAChild*().(SizeofExprOperator).getExprOperand().getType().getSize() > 1
or
this.(SizeofTypeOperator).getTypeOperand().getSize() > 1
exists(this.getValue()) and
this.getAChild*().(SizeofTypeOperator).getTypeOperand().getSize() > 1
or
this instanceof OffsetOfExpr
)
Expand Down
33 changes: 23 additions & 10 deletions c/cert/src/rules/CON30-C/CleanUpThreadSpecificStorage.ql
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,31 @@

import cpp
import codingstandards.c.cert
import codingstandards.cpp.Concurrency
import semmle.code.cpp.dataflow.DataFlow
import codingstandards.cpp.ConcurrencyNew
import semmle.code.cpp.dataflow.new.DataFlow

newtype Direction =
Incoming() or
Outgoing()

predicate isSource(DataFlow::Node node, Direction d) {
exists(TSSCreateFunctionCall tsc, Expr e |
// the only requirement of the source is that at some point
// it refers to the key of a create statement
e.getParent*() = tsc.getKey()
|
d = Outgoing() and
e = [node.asExpr(), node.asDefiningArgument()]
or
d = Incoming() and
e = [node.asExpr(), node.asIndirectArgument()]
)
}

module TssCreateToTssDeleteConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node node) {
exists(TSSCreateFunctionCall tsc, Expr e |
// the only requirement of the source is that at some point
// it refers to the key of a create statement
e.getParent*() = tsc.getKey() and
(e = node.asDefiningArgument() or e = node.asExpr())
)
}
predicate isSource(DataFlow::Node node) { isSource(node, Outgoing()) }

predicate isBarrierIn(DataFlow::Node node) { isSource(node, Incoming()) }

predicate isSink(DataFlow::Node node) {
exists(TSSDeleteFunctionCall tsd, Expr e |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

from ThreadedCFN node
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import cpp
import codingstandards.c.cert
import codingstandards.c.Objects
import codingstandards.cpp.Concurrency
import semmle.code.cpp.dataflow.DataFlow
import codingstandards.cpp.ConcurrencyNew
import semmle.code.cpp.dataflow.new.DataFlow
import semmle.code.cpp.commons.Alloc

from C11ThreadCreateCall tcc, Expr arg
Expand Down Expand Up @@ -53,6 +53,7 @@ where
not exists(TSSSetFunctionCall tss, DataFlow::Node src |
// there should be dataflow from somewhere (the same somewhere)
// into each of the first arguments
exists(Expr e | e = src.asDefinition() or e = src.asDefiningArgument()) and
DataFlow::localFlow(src, DataFlow::exprNode(tsg.getArgument(0))) and
DataFlow::localFlow(src, DataFlow::exprNode(tss.getArgument(0)))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import cpp
import codingstandards.c.cert
import codingstandards.cpp.Concurrency
import semmle.code.cpp.dataflow.DataFlow
import codingstandards.cpp.ConcurrencyNew
import semmle.code.cpp.dataflow.new.DataFlow

from TSSGetFunctionCall tsg, ThreadedFunction tf
where
Expand All @@ -31,7 +31,8 @@ where
// however, there does not exist a proper sequencing.
not exists(TSSSetFunctionCall tss, DataFlow::Node src |
// there should be dataflow from somewhere (the same somewhere)
// into each of the first arguments
// into each of the first argument
exists(Expr e | e = src.asDefinition() or e = src.asDefiningArgument()) and
DataFlow::localFlow(src, DataFlow::exprNode(tsg.getArgument(0))) and
DataFlow::localFlow(src, DataFlow::exprNode(tss.getArgument(0)))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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

from FunctionCall fc
// This should only be applied in the context of a multi-threaded program (since
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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

from MacroInvocation mi, Variable v, Locatable whereFound
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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

from AtomicCompareExchange ace
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import cpp
import codingstandards.c.cert
import codingstandards.c.Objects
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow

class Source extends Expr {
ObjectIdentity rootObject;
Expand All @@ -34,7 +34,7 @@ class Sink extends DataFlow::Node {
Sink() {
//output parameter
exists(Parameter f |
f.getAnAccess() = this.(DataFlow::PostUpdateNode).getPreUpdateNode().asExpr() and
this.isFinalValueOfParameter(f) and
f.getUnderlyingType() instanceof PointerType
)
or
Expand Down
2 changes: 1 addition & 1 deletion c/cert/src/rules/ERR30-C/ErrnoReadBeforeReturn.ql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import cpp
import codingstandards.c.cert
import codingstandards.c.Errno
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow

/**
* A call to an `OutOfBandErrnoSettingFunction`
Expand Down
2 changes: 1 addition & 1 deletion c/cert/src/rules/ERR30-C/SetlocaleMightSetErrno.ql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import cpp
import codingstandards.c.cert
import codingstandards.c.Errno
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow

class SetlocaleFunctionCall extends FunctionCall {
SetlocaleFunctionCall() { this.getTarget().hasGlobalName("setlocale") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import codingstandards.c.cert
import codingstandards.c.Errno
import codingstandards.c.Signal
import semmle.code.cpp.controlflow.Guards
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow

/**
* A check on `signal` call return value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import cpp
import codingstandards.c.cert
import semmle.code.cpp.commons.NULL
import codingstandards.cpp.ReadErrorsAndEOF
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow

ComparisonOperation getAValidComparison(string spec) {
spec = "=0" and result.(EqualityOperation).getAnOperand().getValue() = "0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ class ExplicitComparison extends EffectivelyComparison, FinalComparisonOperation
override FunctionExpr getFunctionExpr() { result = funcExpr }
}

class ImplicitComparison extends EffectivelyComparison, GuardCondition {
class ImplicitComparison extends EffectivelyComparison, GuardCondition instanceof Expr {
ImplicitComparison() {
this.valueControlsEdge(_, _, _) and
this instanceof FunctionExpr and
not getParent() instanceof ComparisonOperation
not super.getParent() instanceof ComparisonOperation
}

override string getExplanation() { result = "$@ undergoes implicit constant comparison." }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import cpp
import codingstandards.c.cert
import codingstandards.cpp.Alignment
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
import ExprWithAlignmentToCStyleCastFlow::PathGraph

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import cpp
import codingstandards.c.cert
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow
import SuspectFunctionPointerToCallFlow::PathGraph

/**
Expand Down Expand Up @@ -61,7 +61,8 @@ where
not isExcluded(src.getNode().asExpr(),
ExpressionsPackage::doNotCallFunctionPointerWithIncompatibleTypeQuery()) and
access = src.getNode().asExpr() and
SuspectFunctionPointerToCallFlow::flowPath(src, sink)
SuspectFunctionPointerToCallFlow::flowPath(src, sink) and
not access.getType() = sink.getNode().asExpr().getFullyConverted().getType()
select src, src, sink,
"Incompatible function $@ assigned to function pointer is eventually called through the pointer.",
access.getTarget(), access.getTarget().getName()
2 changes: 1 addition & 1 deletion c/cert/src/rules/EXP40-C/DoNotModifyConstantObjects.ql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import cpp
import codingstandards.c.cert
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow
import CastFlow::PathGraph
import codingstandards.cpp.SideEffect

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.FgetsErrorManagement
import codingstandards.cpp.Dereferenced
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow

/*
* CFG nodes that follows a successful call to `fgets`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import cpp
import codingstandards.cpp.FgetsErrorManagement
import codingstandards.cpp.Dereferenced
import codingstandards.c.cert
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow

/*
* Models calls to `memcpy` `strcpy` `strncpy` and their wrappers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import cpp
import codingstandards.c.cert
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow

class FgetposCall extends FunctionCall {
FgetposCall() { this.getTarget().hasGlobalOrStdName("fgetpos") }
Expand All @@ -30,12 +30,12 @@ class FsetposCall extends FunctionCall {
module FposDFConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
// source must be the second parameter of a FgetposCall call
source = DataFlow::definitionByReferenceNodeFromArgument(any(FgetposCall c).getArgument(1))
source.asDefiningArgument() = any(FgetposCall c).getArgument(1)
}

predicate isSink(DataFlow::Node sink) {
// sink must be the second parameter of a FsetposCall call
sink.asExpr() = any(FsetposCall c).getArgument(1)
sink.asIndirectExpr() = any(FsetposCall c).getArgument(1)
}
}

Expand All @@ -45,6 +45,6 @@ from FsetposCall fsetpos
where
not isExcluded(fsetpos.getArgument(1),
IO2Package::onlyUseValuesForFsetposThatAreReturnedFromFgetposQuery()) and
not FposDFFlow::flowToExpr(fsetpos.getArgument(1))
not exists(DataFlow::Node n | n.asIndirectExpr() = fsetpos.getArgument(1) | FposDFFlow::flowTo(n))
select fsetpos.getArgument(1),
"The position argument of a call to `fsetpos()` should be obtained from a call to `fgetpos()`."
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import cpp
import codingstandards.c.cert
import codingstandards.cpp.standardlibrary.FileAccess
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow
import semmle.code.cpp.valuenumbering.GlobalValueNumbering

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.Overflow
import semmle.code.cpp.controlflow.Guards
import semmle.code.cpp.dataflow.TaintTracking
import semmle.code.cpp.dataflow.new.TaintTracking
import semmle.code.cpp.models.Models

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import cpp
import codingstandards.c.cert
import codingstandards.cpp.Alignment
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow
import AlignedAllocToReallocFlow::PathGraph

int getStatedValue(Expr e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import cpp
import codingstandards.c.cert
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow

/**
* The argument of a call to `asctime`
Expand All @@ -29,6 +29,8 @@ class AsctimeArg extends Expr {
this =
any(FunctionCall f | f.getTarget().hasGlobalName(["asctime", "asctime_r"])).getArgument(0)
}

DataFlow::Node asSink() { this = result.asIndirectExpr() }
}

/**
Expand All @@ -37,20 +39,20 @@ class AsctimeArg extends Expr {
*/
module TmStructSafeConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node src) {
src.asExpr()
src.asIndirectExpr()
.(FunctionCall)
.getTarget()
.hasGlobalName(["localtime", "localtime_r", "localtime_s", "gmtime", "gmtime_r", "gmtime_s"])
}

predicate isSink(DataFlow::Node sink) { sink.asExpr() instanceof AsctimeArg }
predicate isSink(DataFlow::Node sink) { exists(AsctimeArg arg | arg.asSink() = sink) }
}

module TmStructSafeFlow = DataFlow::Global<TmStructSafeConfig>;

from AsctimeArg fc
where
not isExcluded(fc, Contracts7Package::doNotPassInvalidDataToTheAsctimeFunctionQuery()) and
not TmStructSafeFlow::flowToExpr(fc)
not TmStructSafeFlow::flowTo(fc.asSink())
select fc,
"The function `asctime` and `asctime_r` should be discouraged. Unsanitized input can overflow the output buffer."
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import cpp
import codingstandards.c.cert
import codingstandards.c.Signal
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.new.DataFlow

/**
* Does not access an external variable except
Expand Down
Loading
Loading