Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
41382dd
C#: A regression test for extractor crash when wrong expression type …
calumgrant Aug 23, 2018
71483c7
CPP: Remove some empty source files.
geoffw0 Sep 4, 2018
c204ec3
C++: Enhance qualifiers/class-enum test
ian-semmle Sep 5, 2018
ca082be
C++: Fix spurious extra qualified names for enum constants within a c…
ian-semmle Sep 5, 2018
4d8a6e5
Merge pull request #156 from geoffw0/empty-file
jbj Sep 6, 2018
3d3b7b0
JS: fix typo in test case
Sep 6, 2018
04f2995
Merge pull request #98 from calumgrant/cs/literal-conversion-fix
hvitved Sep 7, 2018
6bfbd21
Merge pull request #159 from ian-semmle/EnumConstant
jbj Sep 8, 2018
b6b3581
Merge pull request #168 from esben-semmle/js/fix-test-case-typo
semmle-qlci Sep 9, 2018
70e7131
Merge branch 'rc/1.18' into merge-rc
hvitved Sep 11, 2018
ecfc536
C++: IR: InstructionSanity::duplicateOperand perf
jbj Sep 11, 2018
3c3cc2e
Merge pull request #175 from hvitved/merge-rc
jbj Sep 11, 2018
628d7b9
Merge pull request #178 from jbj/ir-duplicateOperand-perf
ian-semmle Sep 11, 2018
d956bf9
C++: Document the three predicates for array size
jbj Sep 11, 2018
4304a4e
C++: Fix docs copy-paste error
jbj Sep 11, 2018
43c65e0
JS: classify bundle files based on multiple license comments
Sep 11, 2018
49b8db9
Merge pull request #180 from jbj/ArrayType-size-docs
dave-bartolomeo Sep 11, 2018
9e0ba51
Merge pull request #179 from esben-semmle/js/classify-multi-license-fix
semmle-qlci Sep 11, 2018
9fb5fbd
C++: Restructure UnsafeUseOfStrcat for performance
jbj Sep 12, 2018
ccbd8aa
Java: Improve alert message of IntMultToLong.
aschackmull Sep 12, 2018
1bbc67b
Java: Autoformat query.
aschackmull Sep 12, 2018
1459b98
Merge pull request #183 from jbj/unsafe-strcat-perf
geoffw0 Sep 12, 2018
b9acdf5
Java: Update qltest.
aschackmull Sep 13, 2018
3d02229
Merge pull request #186 from Semmle/rc/1.18
semmle-qlci Sep 13, 2018
6266d8b
Merge pull request #184 from aschackmull/java/intmulttolong-message
semmle-qlci Sep 13, 2018
9886e4a
Merge remote-tracking branch 'upstream/master' into merge-master-next…
jbj Sep 13, 2018
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
Empty file.
1 change: 0 additions & 1 deletion cpp/ql/src/Documentation/UncommentedFunction.cpp

This file was deleted.

1 change: 0 additions & 1 deletion cpp/ql/src/Likely Bugs/Arithmetic/BadCheckOdd.cpp

This file was deleted.

1 change: 0 additions & 1 deletion cpp/ql/src/Likely Bugs/Arithmetic/BitwiseSignCheck.cpp

This file was deleted.

19 changes: 14 additions & 5 deletions cpp/ql/src/Likely Bugs/Memory Management/UnsafeUseOfStrcat.ql
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ predicate isEffectivelyConstAccess(VariableAccess a)
)
}

from FunctionCall fc, VariableAccess src
where fc.getTarget().hasName("strcat") and
src = fc.getArgument(1) and
not src.getType() instanceof ArrayType and
class StrcatSource extends VariableAccess {
FunctionCall strcat;

StrcatSource() {
strcat.getTarget().hasName("strcat") and
this = strcat.getArgument(1)
}

FunctionCall getStrcatCall() { result = strcat }
}

from StrcatSource src
where not src.getType() instanceof ArrayType and
not exists(BufferSizeExpr bse |
bse.getArg().(VariableAccess).getTarget() = src.getTarget()) and
not isEffectivelyConstAccess(src)
select fc, "Always check the size of the source buffer when using strcat."
select src.getStrcatCall(), "Always check the size of the source buffer when using strcat."
1 change: 1 addition & 0 deletions cpp/ql/src/semmle/code/cpp/Declaration.qll
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ abstract class Declaration extends Locatable, @declaration {
// MemberFunction, MemberVariable, MemberType
exists (Declaration m
| m = this and
not m instanceof EnumConstant and
result = m.getDeclaringType().getQualifiedName() + "::" + m.getName())
or
exists (EnumConstant c
Expand Down
14 changes: 12 additions & 2 deletions cpp/ql/src/semmle/code/cpp/Type.qll
Original file line number Diff line number Diff line change
Expand Up @@ -904,15 +904,25 @@ class ArrayType extends DerivedType {
ArrayType() { derivedtypes(underlyingElement(this),_,4,_) }

predicate hasArraySize() { arraysizes(underlyingElement(this),_,_,_) }

/**
* Gets the number of elements in this array. Only has a result for arrays declared to be of a
* constant size. See `getByteSize` for getting the number of bytes.
*/
int getArraySize() { arraysizes(underlyingElement(this),result,_,_) }

/**
* Gets the byte size of this array. Only has a result for arrays declared to be of a constant
* size. See `getArraySize` for getting the number of elements.
*/
int getByteSize() { arraysizes(underlyingElement(this),_,result,_) }

override int getAlignment() { arraysizes(underlyingElement(this), _, _, result) }

/**
* Gets the size of this array (only valid for arrays declared to be of a constant
* size, will fail for all others).
* Gets the byte size of this array. Only has a result for arrays declared to be of a constant
* size. This predicate is a synonym for `getByteSize`. See `getArraySize` for getting the number
* of elements.
*/
override int getSize() {
result = this.getByteSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module InstructionSanity {
* Holds if instruction `instr` has multiple operands with tag `tag`.
*/
query predicate duplicateOperand(Instruction instr, OperandTag tag) {
count(instr.getOperand(tag)) > 1 and
strictcount(instr.getOperand(tag)) > 1 and
not tag instanceof UnmodeledUseOperand
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module InstructionSanity {
* Holds if instruction `instr` has multiple operands with tag `tag`.
*/
query predicate duplicateOperand(Instruction instr, OperandTag tag) {
count(instr.getOperand(tag)) > 1 and
strictcount(instr.getOperand(tag)) > 1 and
not tag instanceof UnmodeledUseOperand
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module InstructionSanity {
* Holds if instruction `instr` has multiple operands with tag `tag`.
*/
query predicate duplicateOperand(Instruction instr, OperandTag tag) {
count(instr.getOperand(tag)) > 1 and
strictcount(instr.getOperand(tag)) > 1 and
not tag instanceof UnmodeledUseOperand
}

Expand Down
21 changes: 21 additions & 0 deletions cpp/ql/test/library-tests/qualifiers/class-enum/decls.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
| file://:0:0:0:0 | __va_list_tag | __va_list_tag |
| file://:0:0:0:0 | fp_offset | __va_list_tag::fp_offset |
| file://:0:0:0:0 | gp_offset | __va_list_tag::gp_offset |
| file://:0:0:0:0 | operator= | __va_list_tag::operator= |
| file://:0:0:0:0 | operator= | __va_list_tag::operator= |
| file://:0:0:0:0 | overflow_arg_area | __va_list_tag::overflow_arg_area |
| file://:0:0:0:0 | reg_save_area | __va_list_tag::reg_save_area |
| test.cpp:2:7:2:7 | operator= | MyEnumClass::operator= |
| test.cpp:2:7:2:7 | operator= | MyEnumClass::operator= |
| test.cpp:2:7:2:17 | MyEnumClass | MyEnumClass |
| test.cpp:4:10:4:15 | MyEnum | MyEnumClass::MyEnum |
| test.cpp:5:9:5:9 | A | MyEnumClass::MyEnum::A |
| test.cpp:6:9:6:9 | B | MyEnumClass::MyEnum::B |
| test.cpp:10:34:10:34 | v | v |
| test.cpp:12:7:12:7 | MyClass2 | MyClass2::MyClass2 |
| test.cpp:12:7:12:7 | MyClass2 | MyClass2::MyClass2 |
| test.cpp:12:7:12:7 | operator= | MyClass2::operator= |
| test.cpp:12:7:12:7 | operator= | MyClass2::operator= |
| test.cpp:12:7:12:14 | MyClass2 | MyClass2 |
| test.cpp:14:12:14:19 | MyClass2 | MyClass2::MyClass2 |
| test.cpp:17:6:17:6 | f | f |
5 changes: 5 additions & 0 deletions cpp/ql/test/library-tests/qualifiers/class-enum/decls.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import cpp

from Declaration d
select d, d.getQualifiedName()

13 changes: 13 additions & 0 deletions csharp/ql/test/library-tests/regressions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,16 @@ void F()
new Point() { Name = "Bob" };
}
}

class LiteralConversions
{
struct Point
{
public int? x, y;
}

void F()
{
new Point { x=1, y=2 };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@
| Program.cs:101:16:101:21 | Object |
| Program.cs:104:5:104:8 | Void |
| Program.cs:106:13:106:17 | Point |
| Program.cs:114:16:114:18 | Int32 |
| Program.cs:114:16:114:18 | Int32 |
| Program.cs:114:16:114:19 | Nullable<Int32> |
| Program.cs:114:16:114:19 | Nullable<Int32> |
| Program.cs:117:5:117:8 | Void |
| Program.cs:119:13:119:17 | Point |
9 changes: 7 additions & 2 deletions java/ql/src/Likely Bugs/Arithmetic/IntMultToLong.ql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* external/cwe/cwe-197
* external/cwe/cwe-681
*/

import java
import semmle.code.java.dataflow.RangeUtils
import semmle.code.java.Conversions
Expand All @@ -25,7 +26,8 @@ predicate small(MulExpr e) {
lhs = e.getLeftOperand().getProperExpr().(ConstantIntegerExpr).getIntValue() and
rhs = e.getRightOperand().getProperExpr().(ConstantIntegerExpr).getIntValue() and
lhs * rhs = res and
t.getOrdPrimitiveType().getMinValue() <= res and res <= t.getOrdPrimitiveType().getMaxValue()
t.getOrdPrimitiveType().getMinValue() <= res and
res <= t.getOrdPrimitiveType().getMaxValue()
)
}

Expand All @@ -52,4 +54,7 @@ where
// not obviously small and ok
not small(e) and
e.getEnclosingCallable().fromSource()
select c, "$@ converted to "+ destType.getName() +" by use in " + ("a " + c.kind()).regexpReplaceAll("^a ([aeiou])", "an $1") + ".", e, sourceType.getName() + " multiplication"
select c,
"Potential overflow in $@ before it is converted to " + destType.getName() + " by use in " +
("a " + c.kind()).regexpReplaceAll("^a ([aeiou])", "an $1") + ".", e,
sourceType.getName() + " multiplication"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
| Test.java:20:23:20:48 | ... * ... | $@ converted to long by use in an assignment context. | Test.java:20:23:20:48 | ... * ... | int multiplication |
| Test.java:27:23:27:52 | ... + ... | $@ converted to long by use in an assignment context. | Test.java:27:23:27:48 | ... * ... | int multiplication |
| Test.java:34:23:34:63 | ...?...:... | $@ converted to long by use in an assignment context. | Test.java:34:30:34:55 | ... * ... | int multiplication |
| Test.java:41:25:41:49 | ... * ... | $@ converted to double by use in an assignment context. | Test.java:41:25:41:49 | ... * ... | long multiplication |
| Test.java:20:23:20:48 | ... * ... | Potential overflow in $@ before it is converted to long by use in an assignment context. | Test.java:20:23:20:48 | ... * ... | int multiplication |
| Test.java:27:23:27:52 | ... + ... | Potential overflow in $@ before it is converted to long by use in an assignment context. | Test.java:27:23:27:48 | ... * ... | int multiplication |
| Test.java:34:23:34:63 | ...?...:... | Potential overflow in $@ before it is converted to long by use in an assignment context. | Test.java:34:30:34:55 | ... * ... | int multiplication |
| Test.java:41:25:41:49 | ... * ... | Potential overflow in $@ before it is converted to double by use in an assignment context. | Test.java:41:25:41:49 | ... * ... | long multiplication |
7 changes: 7 additions & 0 deletions javascript/ql/src/semmle/javascript/frameworks/Bundling.qll
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,20 @@ Comment getExclamationPointCommentInRun(ExclamationPointComment head) {
* Holds if this is a bundle containing multiple licenses.
*/
predicate isMultiLicenseBundle(TopLevel tl) {
// case: comments preserved by minifiers
count(ExclamationPointComment head |
head.getTopLevel() = tl and
exists(ExclamationPointComment licenseIndicator |
licenseIndicator = getExclamationPointCommentInRun(head) and
licenseIndicator.getLine(_).regexpMatch("(?i).*\\b(copyright|license|\\d+\\.\\d+)\\b.*")
)
) > 1
or
// case: ordinary block comments with "@license" lines
count(BlockComment head |
head.getTopLevel() = tl and
head.getLine(_).regexpMatch("(?i) *\\* @license .*")
) > 1
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var express = require('express');
var app = express();
var URI = reuires("urijs");
var URI = require("urijs");
app.get('/findKey', function(req, res) {
var key = req.param("key"), input = req.param("input");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| jsx.js:0:0:0:0 | jsx.js | generated |
| multi-part-bundle.html:0:0:0:0 | multi-part-bundle.html | generated |
| multi-part-bundle.js:0:0:0:0 | multi-part-bundle.js | generated |
| multiple-licenses-2.js:0:0:0:0 | multiple-licenses-2.js | generated |
| multiple-licenses.js:0:0:0:0 | multiple-licenses.js | generated |
| opal-test.js:0:0:0:0 | opal-test.js | generated |
| peg-js.js:0:0:0:0 | peg-js.js | generated |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* @copyright (c) ...
* @copyright (c) ...
* @license ...
*/

/**
* @copyright ...
* @license ...
*/