Skip to content

Commit 682ef75

Browse files
committed
C++: Port the final part of the negation to the new module.
1 parent c4723c8 commit 682ef75

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

cpp/ql/src/Likely Bugs/Leap Year/UncheckedReturnValueForTimeFunctions.ql

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,24 @@ module SafeTimeGatheringFunctionCallToModifiedFieldAccessConfig implements Input
139139
module SafeTimeGatheringFunctionCallToModifiedFieldAccess =
140140
ControlFlowReachability<SafeTimeGatheringFunctionCallToModifiedFieldAccessConfig>;
141141

142+
module ModifiedMonthFieldAccessToTimeConversionConfig implements InputSig {
143+
predicate isSource(ControlFlowNode n) {
144+
exists(Variable var, MonthFieldAccess mfa, AssignExpr ae |
145+
n = mfa and
146+
isUnpackedTimeTypeVar(var, _, _) and
147+
mfa.getQualifier() = var.getAnAccess() and
148+
mfa.isModified() and
149+
ae = mfa.getEnclosingElement() and
150+
ae.getAnOperand().getValue().toInt() = 1
151+
)
152+
}
153+
154+
predicate isSink(ControlFlowNode fcall) { ModifiedFieldAccessToTimeConversion::flowsTo(_, fcall) }
155+
}
156+
157+
module ModifiedMonthFieldAccessToTimeConversion =
158+
ControlFlowReachability<ModifiedMonthFieldAccessToTimeConversionConfig>;
159+
142160
from FunctionCall fcall, TimeConversionFunction trf, Variable var
143161
where
144162
isUnpackedTimeTypeVar(var, fcall, trf) and
@@ -158,13 +176,7 @@ where
158176
)
159177
or
160178
// Remove any instance where the year is changed, but the month is set to 1 (year wrapping)
161-
exists(MonthFieldAccess mfa, AssignExpr ae |
162-
mfa.getQualifier() = var.getAnAccess() and
163-
mfa.isModified() and
164-
mfa = fcall.getAPredecessor*() and
165-
ae = mfa.getEnclosingElement() and
166-
ae.getAnOperand().getValue().toInt() = 1
167-
)
179+
ModifiedMonthFieldAccessToTimeConversion::isSink(fcall)
168180
)
169181
select fcall,
170182
"$@: Return value of $@ function should be verified to check for any error because variable $@ is not guaranteed to be safe.",

0 commit comments

Comments
 (0)