Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69e9156

Browse files
committed
Merge branch 'master-to-next-20180905-master' into master-to-next-20180905
2 parents 8fbc191 + d5e0357 commit 69e9156

14 files changed

Lines changed: 125 additions & 63 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Improvements to JavaScript analysis
2+
3+
## General improvements
4+
5+
## New queries
6+
7+
| **Query** | **Tags** | **Purpose** |
8+
|-----------------------------|-----------|--------------------------------------------------------------------|
9+
| *@name of query (Query ID)* | *Tags* |*Aim of the new query and whether it is enabled by default or not* |
10+
11+
## Changes to existing queries
12+
13+
| **Query** | **Expected impact** | **Change** |
14+
|--------------------------------|----------------------------|----------------------------------------------|
15+
| Regular expression injection | Fewer false-positive results | This rule now identifies calls to `String.prototype.search` with more precision. |
16+
17+
18+
## Changes to QL libraries

cpp/ql/src/Likely Bugs/Arithmetic/IntMultToLong.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ where t1 = me.getType().getUnderlyingType() and
103103
) and
104104
e.(Literal).getType().getSize() = t2.getSize()
105105
)
106-
select me, "Cast to '" + me.getFullyConverted().getType().toString() + "' before multiplication to avoid potential overflow."
106+
select me, "Multiplication result may overflow '" + me.getType().toString() + "' before it is converted to '" + me.getFullyConverted().getType().toString() + "'."

cpp/ql/src/semmle/code/cpp/Declaration.qll

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,24 @@ abstract class Declaration extends Locatable, @declaration {
8787

8888
override string toString() { result = this.getName() }
8989

90-
/** Gets the name of this declaration. */
90+
/**
91+
* Gets the name of this declaration.
92+
*
93+
* This name doesn't include a namespace or any argument types, so
94+
* for example both functions `::open()` and `::std::ifstream::open(...)`
95+
* have the same name.
96+
*
97+
* To get the name including the namespace, use `getQualifiedName` or
98+
* `hasQualifiedName`.
99+
*
100+
* To test whether this declaration has a particular name in the global
101+
* namespace, use `hasGlobalName`.
102+
*/
91103
abstract string getName();
104+
/** Holds if this declaration has the given name. */
92105
predicate hasName(string name) { name = this.getName() }
93106

94-
/** Holds if this element has the given name in the global namespace. */
107+
/** Holds if this declaration has the given name in the global namespace. */
95108
predicate hasGlobalName(string name) {
96109
hasName(name)
97110
and getNamespace() instanceof GlobalNamespace

cpp/ql/src/semmle/code/cpp/Function.qll

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@ private import semmle.code.cpp.internal.ResolveClass
1717
* in more detail in `Declaration.qll`.
1818
*/
1919
class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
20-
21-
/**
22-
* Gets the name of this function.
23-
*
24-
* This name doesn't include a namespace or any argument types, so both
25-
* `::open()` and `::std::ifstream::open(...)` have the same name.
26-
*
27-
* To get the name including the namespace, use `getQualifiedName` or
28-
* `hasQualifiedName`.
29-
*
30-
* To test whether a function has a particular name in the global
31-
* namespace, use `hasGlobalName`.
32-
*/
3320
override string getName() { functions(underlyingElement(this),result,_) }
3421

3522
/**

cpp/ql/src/semmle/code/cpp/Namespace.qll

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,6 @@ class GlobalNamespace extends Namespace {
190190

191191
override Declaration getADeclaration() {
192192
suppressWarningForUnused(this) and
193-
not exists(DeclStmt d |
194-
d.getADeclaration() = result and
195-
not result instanceof Function
196-
) and
197-
not exists(ConditionDeclExpr cde | cde.getVariable() = result) and
198193
result.isTopLevel() and
199194
not namespacembrs(_, unresolveElement(result))
200195
}

cpp/ql/src/semmle/code/cpp/Type.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,8 +1155,6 @@ class TemplateParameter extends UserType
11551155
{
11561156
TemplateParameter() { usertypes(underlyingElement(this), _, 7) or usertypes(underlyingElement(this), _, 8) }
11571157

1158-
override string getName() { usertypes(underlyingElement(this), result, _) }
1159-
11601158
override predicate involvesTemplateParameter() {
11611159
any()
11621160
}

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/IRBlockConstruction.qll

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,29 @@ private cached module Cached {
3232
startsBasicBlock(firstInstr)
3333
}
3434

35+
/** Holds if `i2` follows `i1` in a `IRBlock`. */
36+
private predicate adjacentInBlock(Instruction i1, Instruction i2) {
37+
exists(GotoEdge edgeKind | i2 = i1.getSuccessor(edgeKind)) and
38+
not startsBasicBlock(i2)
39+
}
40+
41+
/** Gets the index of `i` in its `IRBlock`. */
42+
private int getMemberIndex(Instruction i) {
43+
startsBasicBlock(i) and
44+
result = 0
45+
or
46+
exists(Instruction iPrev |
47+
adjacentInBlock(iPrev, i) and
48+
result = getMemberIndex(iPrev) + 1
49+
)
50+
}
51+
52+
/** Holds if `i` is the `index`th instruction in `block`. */
3553
cached Instruction getInstruction(TIRBlock block, int index) {
36-
index = 0 and block = MkIRBlock(result) or
37-
(
38-
index > 0 and
39-
not startsBasicBlock(result) and
40-
exists(Instruction predecessor, GotoEdge edge |
41-
predecessor = getInstruction(block, index - 1) and
42-
result = predecessor.getSuccessor(edge)
43-
)
54+
exists(Instruction first |
55+
block = MkIRBlock(first) and
56+
index = getMemberIndex(result) and
57+
adjacentInBlock*(first, result)
4458
)
4559
}
4660

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | __va_list_tag | __va_list_tag |
2-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | fp_offset | __va_list_tag::fp_offset |
3-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | gp_offset | __va_list_tag::gp_offset |
4-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | operator= | __va_list_tag::operator= |
5-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | operator= | __va_list_tag::operator= |
6-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | overflow_arg_area | __va_list_tag::overflow_arg_area |
7-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | reg_save_area | __va_list_tag::reg_save_area |
8-
| file://:0:0:0:0 | B | namespaces.cpp:32:7:32:7 | x | B::x |
9-
| namespaces.cpp:11:13:11:13 | C::D | file://:0:0:0:0 | p#0 | <none> |
10-
| namespaces.cpp:11:13:11:13 | C::D | file://:0:0:0:0 | p#0 | <none> |
11-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:13:17:13:17 | f | C::D::f |
12-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:15:12:15:12 | E | C::D::E |
13-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:15:12:15:12 | operator= | C::D::E::operator= |
14-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:15:12:15:12 | operator= | C::D::E::operator= |
15-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:17:12:17:12 | g | C::D::E::g |
16-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:17:18:17:18 | p | <none> |
17-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:18:12:18:12 | a | <none> |
18-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:20:13:20:13 | b | <none> |
1+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | __va_list_tag | __va_list_tag | true |
2+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | fp_offset | __va_list_tag::fp_offset | false |
3+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | gp_offset | __va_list_tag::gp_offset | false |
4+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | operator= | __va_list_tag::operator= | false |
5+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | operator= | __va_list_tag::operator= | false |
6+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | overflow_arg_area | __va_list_tag::overflow_arg_area | false |
7+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | reg_save_area | __va_list_tag::reg_save_area | false |
8+
| file://:0:0:0:0 | (global namespace) | namespaces.cpp:40:5:40:13 | globalInt | globalInt | true |
9+
| file://:0:0:0:0 | (global namespace) | namespaces.cpp:42:6:42:18 | globalIntUser | globalIntUser | true |
10+
| file://:0:0:0:0 | <none> | file://:0:0:0:0 | auto | <none> | false |
11+
| file://:0:0:0:0 | B | namespaces.cpp:32:7:32:7 | x | B::x | true |
12+
| namespaces.cpp:11:13:11:13 | C::D | file://:0:0:0:0 | p#0 | <none> | false |
13+
| namespaces.cpp:11:13:11:13 | C::D | file://:0:0:0:0 | p#0 | <none> | false |
14+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:13:17:13:17 | f | C::D::f | true |
15+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:15:12:15:12 | E | C::D::E | true |
16+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:15:12:15:12 | operator= | C::D::E::operator= | false |
17+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:15:12:15:12 | operator= | C::D::E::operator= | false |
18+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:17:12:17:12 | g | C::D::E::g | false |
19+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:17:18:17:18 | p | <none> | false |
20+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:18:12:18:12 | a | <none> | false |
21+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:20:13:20:13 | b | <none> | false |

cpp/ql/test/library-tests/namespaces/namespaces/decls.ql

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,24 @@ string qual(Declaration d) {
66
else result = "<none>"
77
}
88

9-
from Namespace n, Declaration d
10-
where n = d.getNamespace()
11-
select n, d, qual(d)
9+
newtype TMaybeNamespace = SomeNamespace(Namespace ns) or NoNamespace()
1210

11+
class MaybeNamespace extends TMaybeNamespace {
12+
string toString() {
13+
this = NoNamespace() and result = "<none>"
14+
or
15+
exists(Namespace ns | this = SomeNamespace(ns) and result = ns.toString())
16+
}
17+
18+
Location getLocation() {
19+
exists(Namespace ns |
20+
this = SomeNamespace(ns) and result = ns.getLocation())
21+
}
22+
}
23+
24+
from MaybeNamespace n, Declaration d
25+
where n = SomeNamespace(d.getNamespace())
26+
or n = NoNamespace() and not exists(d.getNamespace())
27+
select n, d,
28+
qual(d),
29+
any(boolean b | if d.isTopLevel() then b = true else b = false)

cpp/ql/test/library-tests/namespaces/namespaces/namespaces.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ namespace B {
3636
namespace std {
3737

3838
}
39+
40+
int globalInt;
41+
42+
void globalIntUser(void) {
43+
extern int globalInt;
44+
}

0 commit comments

Comments
 (0)