Skip to content

Commit 1d9fc8a

Browse files
authored
Merge branch 'main' into sashabu/repeated-initializers
2 parents ddd44b4 + ecf92f0 commit 1d9fc8a

File tree

11 files changed

+73
-58
lines changed

11 files changed

+73
-58
lines changed

cpp/ql/lib/experimental/semmle/code/cpp/semantic/analysis/RangeAnalysisStage.qll

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,15 @@ import experimental.semmle.code.cpp.semantic.SemanticLocation
7878
/**
7979
* Holds if `typ` is a small integral type with the given lower and upper bounds.
8080
*/
81-
private predicate typeBound(SemIntegerType typ, int lowerbound, int upperbound) {
81+
private predicate typeBound(SemIntegerType typ, float lowerbound, float upperbound) {
8282
exists(int bitSize | bitSize = typ.getByteSize() * 8 |
83-
bitSize < 32 and
84-
(
85-
if typ.isSigned()
86-
then (
87-
upperbound = 1.bitShiftLeft(bitSize - 1) - 1 and
88-
lowerbound = -upperbound - 1
89-
) else (
90-
lowerbound = 0 and
91-
upperbound = 1.bitShiftLeft(bitSize) - 1
92-
)
83+
if typ.isSigned()
84+
then (
85+
upperbound = 2.pow(bitSize - 1) - 1 and
86+
lowerbound = -upperbound - 1
87+
) else (
88+
lowerbound = 0 and
89+
upperbound = 2.pow(bitSize) - 1
9390
)
9491
)
9592
}
@@ -286,10 +283,10 @@ module RangeStage<DeltaSig D, BoundSig<D> Bounds, LangSig<D> LangParam, UtilSig<
286283
}
287284

288285
/** Gets the lower bound of the resulting type. */
289-
int getLowerBound() { typeBound(getTrackedType(this), result, _) }
286+
float getLowerBound() { typeBound(getTrackedType(this), result, _) }
290287

291288
/** Gets the upper bound of the resulting type. */
292-
int getUpperBound() { typeBound(getTrackedType(this), _, result) }
289+
float getUpperBound() { typeBound(getTrackedType(this), _, result) }
293290
}
294291

295292
private module SignAnalysisInstantiated = SignAnalysis<D, UtilParam>; // TODO: will this cause reevaluation if it's instantiated with the same DeltaSig and UtilParam multiple times?

cpp/ql/src/Likely Bugs/Memory Management/SuspiciousCallToStrncat.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ predicate case1(FunctionCall fc, Expr sizeArg, VariableAccess destArg) {
4848
* Holds if `fc` is a call to `strncat` with size argument `sizeArg` and destination
4949
* argument `destArg`, and `sizeArg` computes the value `sizeof (dest) - strlen (dest)`.
5050
*/
51-
predicate case2(FunctionCall fc, Expr sizeArg, VariableAccess destArg) {
52-
interestingCallWithArgs(fc, sizeArg, destArg) and
51+
predicate case2(FunctionCall fc, Expr sizeArg, Expr destArg) {
52+
interestingCallWithArgs(fc, pragma[only_bind_into](sizeArg), pragma[only_bind_into](destArg)) and
5353
exists(SubExpr sub, int n |
5454
// The destination buffer is an array of size n
55-
destArg.getUnspecifiedType().(ArrayType).getSize() = n and
55+
pragma[only_bind_out](destArg.getUnspecifiedType().(ArrayType).getSize()) = n and
5656
// The size argument is equivalent to a subtraction
5757
globalValueNumber(sizeArg).getAnExpr() = sub and
5858
// ... where the left side of the subtraction is the constant n

cpp/ql/test/library-tests/ir/range-analysis/SimpleRangeAnalysis_tests.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,11 @@ unsigned int test_ternary01(unsigned int x) {
566566
y1 = x < 100 ?
567567
(range(x), x) : // $ range=<=99
568568
(range(x), 10); // $ range=>=100
569-
range(y1);
569+
range(y1); // $ range=<=99
570570
y2 = x >= 100 ?
571571
(range(x), 10) : // $ range=>=100
572572
(range(x), x); // $ range=<=99
573-
range(y2);
573+
range(y2); // $ range=<=99
574574
y3 = 0;
575575
y4 = 0;
576576
y5 = 0;
@@ -580,14 +580,14 @@ unsigned int test_ternary01(unsigned int x) {
580580
if (x < 300) {
581581
range(x); // $ range=<=299
582582
y3 = x ?:
583-
(range(x), 5); // y3 < 300
584-
range(y3);
583+
(range(x), 5);
584+
range(y3); // $ range=<=299
585585
y4 = x ?:
586-
(range(x), 500); // y4 <= 500
587-
range(y4);
586+
(range(x), 500);
587+
range(y4); // $ range=<=500
588588
y5 = (x+1) ?:
589589
(range(x), 500); // $ range===-1
590-
range(y5); // y5 <= 300
590+
range(y5); // $ range=<=500
591591
y6 = ((unsigned char)(x+1)) ?:
592592
(range(x), 5); // $ range=<=299
593593
range(y6); // y6 < 256
@@ -608,27 +608,27 @@ unsigned int test_ternary02(unsigned int x) {
608608
y1 = x > 100 ?
609609
(range(x), x) : // $ range=>=101
610610
(range(x), 110); // $ range=<=100
611-
range(y1); // y1 > 100
611+
range(y1); // $ range=>=101
612612
y2 = x <= 100 ?
613613
(range(x), 110) : // $ range=<=100
614614
(range(x), x); // $ range=>=101
615-
range(y2); // y2 > 100
615+
range(y2); // $ range=>=101
616616
y3 = 1000;
617617
y4 = 1000;
618618
y5 = 1000;
619619
if (x >= 300) {
620620
range(x); // $ range=>=300
621621
y3 = (x-300) ?:
622622
(range(x), 5); // $ range===300
623-
range(y3); // y3 >= 0
623+
range(y3); // $ range=>=0
624624
y4 = (x-200) ?:
625625
(range(x), 5); // $ range=<=200 range=>=300
626-
range(y4); // y4 >= 100
626+
range(y4); // $ SPURIOUS: range=>=5 MISSING: range=>=100
627627
y5 = ((unsigned char)(x-200)) ?:
628628
(range(x), 5); // $ range=>=300
629629
range(y5); // y6 >= 0
630630
}
631-
range(y1 + y2 + y3 + y4 + y5); // $ MISSING: range=">=... = ...:... ? ... : ...+0" range=">=call to range+0"
631+
range(y1 + y2 + y3 + y4 + y5); // $ range=">=call to range+207" MISSING: range=">=... = ...:... ? ... : ...+0" range=">=call to range+0"
632632
return y1 + y2 + y3 + y4 + y5;
633633
}
634634

@@ -640,14 +640,14 @@ unsigned int test_comma01(unsigned int x) {
640640
unsigned int y1;
641641
unsigned int y2;
642642
y1 = (++y, y);
643-
range(y1); // $ range="==... ? ... : ...+1"
643+
range(y1); // $ range=<=101 range="==... ? ... : ...+1"
644644
y2 = (y++,
645-
range(y), // $ range="==++ ...:... = ...+1" range="==... ? ... : ...+2"
645+
range(y), // $ range=<=102 range="==++ ...:... = ...+1" range="==... ? ... : ...+2"
646646
y += 3,
647-
range(y), // $ range="==++ ...:... = ...+4" range="==... +++3" range="==... ? ... : ...+5"
647+
range(y), // $ range=<=105 range="==++ ...:... = ...+4" range="==... +++3" range="==... ? ... : ...+5"
648648
y);
649-
range(y2); // $ range="==++ ...:... = ...+4" range="==... +++3" range="==... ? ... : ...+5"
650-
range(y1 + y2); // $ MISSING: range=">=++ ...:... = ...+5" range=">=... +++4" range=">=... += ...:... = ...+1" range=">=... ? ... : ...+6"
649+
range(y2); // $ range=<=105 range="==++ ...:... = ...+4" range="==... +++3" range="==... ? ... : ...+5"
650+
range(y1 + y2); // $ range=<=206 range="<=... ? ... : ...+106" MISSING: range=">=++ ...:... = ...+5" range=">=... +++4" range=">=... += ...:... = ...+1" range=">=... ? ... : ...+6"
651651
return y1 + y2;
652652
}
653653

@@ -683,27 +683,27 @@ int test_unsigned_mult01(unsigned int a, unsigned b) {
683683
range(a); // $ range=<=11 range=>=3
684684
range(b); // $ range=<=23 range=>=5
685685
int r = a*b; // 15 .. 253
686-
range(r);
686+
range(r); // $ range=>=15 range=<=253
687687
total += r;
688-
range(total); // $ MISSING: range=>=1
688+
range(total); // $ range=>=15 range=<=253
689689
}
690690
if (3 <= a && a <= 11 && 0 <= b && b <= 23) {
691691
range(a); // $ range=<=11 range=>=3
692692
range(b); // $ range=<=23 range=>=0
693693
int r = a*b; // 0 .. 253
694-
range(r);
694+
range(r); // $ range=>=0 range=<=253
695695
total += r;
696-
range(total); // $ MISSING: range=">=(unsigned int)...+0" range=>=0
696+
range(total); // $ range=>=0 range=<=506 range=">=(unsigned int)...+0" range="<=(unsigned int)...+253"
697697
}
698698
if (3 <= a && a <= 11 && 13 <= b && b <= 23) {
699699
range(a); // $ range=<=11 range=>=3
700700
range(b); // $ range=<=23 range=>=13
701701
int r = a*b; // 39 .. 253
702-
range(r);
702+
range(r); // $ range=>=39 range=<=253
703703
total += r;
704-
range(total); // $ MISSING: range=">=(unsigned int)...+1" range=>=1
704+
range(total); // $ range=>=39 range=<=759 range=">=(unsigned int)...+39" range="<=(unsigned int)...+506" range="<=(unsigned int)...+253"
705705
}
706-
range(total); // $ MISSING: range=">=(unsigned int)...+0" range=>=0
706+
range(total); // $ range=>=0 range=<=759 range=">=(unsigned int)...+0" range="<=(unsigned int)...+506" range="<=(unsigned int)...+253"
707707
return total;
708708
}
709709

@@ -713,25 +713,25 @@ int test_unsigned_mult02(unsigned b) {
713713
if (5 <= b && b <= 23) {
714714
range(b); // $ range=<=23 range=>=5
715715
int r = 11*b; // 55 .. 253
716-
range(r);
716+
range(r); // $ range=>=55 range=<=253
717717
total += r;
718-
range(total); // $ MISSING: range=>=1
718+
range(total); // $ range=>=55 range=<=253
719719
}
720720
if (0 <= b && b <= 23) {
721721
range(b); // $ range=<=23 range=>=0
722722
int r = 11*b; // 0 .. 253
723-
range(r);
723+
range(r); // $ range=>=0 range=<=253
724724
total += r;
725-
range(total); // $ MISSING: range=">=(unsigned int)...+0" range=>=0
725+
range(total); // $ range=>=0 range=<=506 range=">=(unsigned int)...+0" range="<=(unsigned int)...+253"
726726
}
727727
if (13 <= b && b <= 23) {
728728
range(b); // $ range=<=23 range=>=13
729729
int r = 11*b; // 143 .. 253
730-
range(r);
730+
range(r); // $ range=>=143 range=<=253
731731
total += r;
732-
range(total); // $ MISSING: range=">=(unsigned int)...+1" range=>=1
732+
range(total); // $ range=>=143 range=<=759 range=">=(unsigned int)...+143" range="<=(unsigned int)...+506" range="<=(unsigned int)...+253"
733733
}
734-
range(total); // $ MISSING: range=">=(unsigned int)...+0" range=>=0
734+
range(total); // $ range=>=0 range=<=759 range=">=(unsigned int)...+0" range="<=(unsigned int)...+506" range="<=(unsigned int)...+253"
735735
return total;
736736
}
737737

javascript/ql/src/Security/CWE-916/InsufficientPasswordHash.qhelp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
the hash of a password.
3838
</p>
3939

40-
<sample src="examples/InsufficientPasswordHash.js"/>
40+
<sample src="examples/InsufficientPasswordHash_NodeJS.js"/>
4141

4242
<p>
4343
This is not secure, since the password can be efficiently
@@ -46,7 +46,7 @@
4646
algorithm:
4747
</p>
4848

49-
<sample src="examples/InsufficientPasswordHash_fixed.js"/>
49+
<sample src="examples/InsufficientPasswordHash_NodeJS_fixed.js"/>
5050
</example>
5151

5252
<references>

ql/ql/src/codeql_ql/ast/Ast.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ class Class extends TClass, TypeDeclaration, ModuleDeclaration {
972972
}
973973

974974
/** Gets the class type defined by this class declaration. */
975-
Type getType() { result.getDeclaration() = this }
975+
ClassType getType() { result.getDeclaration() = this }
976976

977977
override AstNode getAChild(string pred) {
978978
result = super.getAChild(pred)

ql/ql/test/type/type.expected

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
| Test.qll:4:15:4:18 | this | Test.qll:3:7:3:13 | Strings |
2-
| Test.qll:4:15:4:18 | this | Test.qll:3:7:3:13 | Strings.Strings |
3-
| Test.qll:4:15:4:18 | this | Test.qll:3:7:3:13 | Strings.extends |
42
| Test.qll:4:22:4:76 | Set | file://:0:0:0:0 | string |
53
| Test.qll:4:23:4:24 | String | file://:0:0:0:0 | string |
64
| Test.qll:4:27:4:29 | String | file://:0:0:0:0 | string |
@@ -13,8 +11,6 @@
1311
| Test.qll:4:66:4:69 | String | file://:0:0:0:0 | string |
1412
| Test.qll:4:72:4:75 | String | file://:0:0:0:0 | string |
1513
| Test.qll:8:14:8:17 | this | Test.qll:7:7:7:12 | Floats |
16-
| Test.qll:8:14:8:17 | this | Test.qll:7:7:7:12 | Floats.Floats |
17-
| Test.qll:8:14:8:17 | this | Test.qll:7:7:7:12 | Floats.extends |
1814
| Test.qll:8:21:8:70 | Set | file://:0:0:0:0 | float |
1915
| Test.qll:8:22:8:24 | Float | file://:0:0:0:0 | float |
2016
| Test.qll:8:27:8:29 | Float | file://:0:0:0:0 | float |
@@ -35,14 +31,10 @@
3531
| Test.qll:13:45:13:49 | AddExpr | file://:0:0:0:0 | float |
3632
| Test.qll:13:49:13:49 | b | Test.qll:7:7:7:12 | Floats |
3733
| Test.qll:16:12:16:15 | this | Test.qll:15:7:15:10 | Base |
38-
| Test.qll:16:12:16:15 | this | Test.qll:15:7:15:10 | Base.Base |
39-
| Test.qll:16:12:16:15 | this | Test.qll:15:7:15:10 | Base.extends |
4034
| Test.qll:16:19:16:23 | String | file://:0:0:0:0 | string |
4135
| Test.qll:18:15:18:20 | result | file://:0:0:0:0 | int |
4236
| Test.qll:18:24:18:24 | Integer | file://:0:0:0:0 | int |
4337
| Test.qll:22:11:22:14 | this | Test.qll:21:7:21:9 | Sub |
44-
| Test.qll:22:11:22:14 | this | Test.qll:21:7:21:9 | Sub.Sub |
45-
| Test.qll:22:11:22:14 | this | Test.qll:21:7:21:9 | Sub.extends |
4638
| Test.qll:22:18:22:22 | String | file://:0:0:0:0 | string |
4739
| Test.qll:24:15:24:20 | result | file://:0:0:0:0 | int |
4840
| Test.qll:24:24:24:33 | Super | Test.qll:15:7:15:10 | Base |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @name Successfully extracted lines
3+
* @description Count all lines in source code in which something was extracted. Entities spanning multiple lines like multi-line strings or comments only contribute one line to this count.
4+
* @kind metric
5+
* @id swift/diagnostics/successfully-extracted-lines
6+
* @tags summary
7+
*/
8+
9+
import swift
10+
11+
select count(File f, int line |
12+
exists(Location loc |
13+
not loc instanceof UnknownLocation and loc.getFile() = f and loc.getStartLine() = line
14+
)
15+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| 4 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
diagnostics/SuccessfullyExtractedLines.ql
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//codeql-extractor-env: CODEQL_EXTRACTOR_SWIFT_RUN_UNDER=true
2+
3+
func not_compiled() {}

0 commit comments

Comments
 (0)