Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brodes/open source query transition #155

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -11,7 +11,7 @@ It is not safe to assume that a year is 365 days long.</p>

<recommendation>
<p>Determine whether the time span in question contains a leap day, then perform the calculation using the correct number
of days. Alternatively, use an established library routine that already contains correct leap year logic.</p>
of days. Alternatively, use an established library routine that already contains correct leap year logic.</p>
</recommendation>

<references>
Expand Down
8 changes: 5 additions & 3 deletions cpp/ql/src/Likely Bugs/Leap Year/Adding365DaysPerYear.ql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* value of 365, it may be a sign that leap years are not taken
* into account.
* @kind problem
* @problem.severity warning
* @problem.severity error
* @id cpp/leap-year/adding-365-days-per-year
* @precision medium
* @tags leap-year
Expand All @@ -13,11 +13,13 @@

import cpp
import LeapYear
import semmle.code.cpp.dataflow.new.DataFlow

from Expr source, Expr sink
where
PossibleYearArithmeticOperationCheckFlow::flow(DataFlow::exprNode(source),
DataFlow::exprNode(sink))
select sink,
"An arithmetic operation $@ that uses a constant value of 365 ends up modifying this date/time, without considering leap year scenarios.",
source, source.toString()
"$@: This arithmetic operation $@ uses a constant value of 365 ends up modifying the date/time located at $@, without considering leap year scenarios.",
sink.getEnclosingFunction(), sink.getEnclosingFunction().toString(), source, source.toString(),
sink, sink.toString()
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @name Leap Year Invalid Check (AntiPattern 5)
* @description An expression is used to check a year is presumably a leap year, but the conditions used are insufficient.
* @kind problem
* @problem.severity warning
* @id cpp/leap-year/invalid-leap-year-check
* @precision medium
* @tags leap-year
* correctness
*/

import cpp
import LeapYear

from Mod4CheckedExpr exprMod4
where not exists(ExprCheckLeapYear lyCheck | lyCheck.getAChild*() = exprMod4)
select exprMod4, "Possible Insufficient Leap Year check (AntiPattern 5)"
Loading
Loading