Skip to content

Commit 7b5163c

Browse files
committed
init precise version
1 parent e63e19b commit 7b5163c

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ abstract class YearWriteOp extends Operation {
6262
or
6363
// If there is a successor or predecessor that sets the month or day to a fixed value
6464
exists(FieldAccess mfa, AssignExpr ae, int val |
65-
mfa instanceof MonthFieldAccess or mfa instanceof DayFieldAccess
66-
|
65+
(mfa instanceof MonthFieldAccess or mfa instanceof DayFieldAccess) and
6766
mfa.getQualifier() = var.getAnAccess() and
6867
mfa.isModified() and
6968
(

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,46 @@ class YearFieldAssignmentAccess extends YearFieldAssignment{
100100
}
101101

102102
/**
103-
*
103+
* A year field assignment, by a unary operator ie `x++`.
104104
*/
105105
class YearFieldAssignmentUnary extends YearFieldAssignment instanceof UnaryArithmeticOperation{
106106
YearFieldAssignmentUnary(){
107-
this.getOperand() instanceof YearFieldAccess and
107+
this.getOperand() instanceof YearFieldAccess
108+
}
109+
}
110+
111+
class MonthOrDayFieldAccess extends FieldAccess{
112+
MonthOrDayFieldAccess(){
113+
this instanceof MonthFieldAccess
114+
or
115+
this instanceof DayFieldAccess
116+
}
117+
}
118+
119+
/**
120+
* A static assignment to the day or month access
121+
*
122+
* ```
123+
* a.day = 28;
124+
* ```
125+
*/
126+
class GoodExpr extends YearFieldAssignment{
127+
GoodExpr(){
128+
exists(Variable var, VariableAccess va, YearFieldAccess yfa |
129+
// yfa = this.getYearAccess() and
130+
yfa.getQualifier() = va and
131+
var.getAnAccess() = va and
132+
exists(MonthOrDayFieldAccess mfa, AssignExpr ae, int val |
133+
mfa.getQualifier() = var.getAnAccess() and
134+
mfa.isModified() and
135+
(
136+
mfa.getBasicBlock() = yfa.getBasicBlock().getASuccessor*() or
137+
yfa.getBasicBlock() = mfa.getBasicBlock().getASuccessor+()
138+
) and
139+
ae = mfa.getEnclosingElement() and
140+
ae.getAnOperand().getValue().toInt() = val
141+
)
142+
)
108143
}
109144
}
110145

0 commit comments

Comments
 (0)