Skip to content

Commit 0fbcfe3

Browse files
authored
Merge branch 'main' into add-php-support
2 parents 6d2a00c + 6fa6093 commit 0fbcfe3

File tree

102 files changed

+22836
-8274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+22836
-8274
lines changed

csharp/ql/src/Bad Practices/PathCombine.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
2-
* @name Call to System.IO.Path.Combine
3-
* @description Finds calls to System.IO.Path's Combine method
2+
* @name Call to 'System.IO.Path.Combine' may silently drop its earlier arguments
3+
* @description 'Path.Combine' may silently drop its earlier arguments
4+
* if its later arguments are absolute paths.
45
* @kind problem
56
* @problem.severity recommendation
67
* @precision very-high
@@ -15,4 +16,4 @@ import semmle.code.csharp.frameworks.System
1516

1617
from MethodCall call
1718
where call.getTarget().hasFullyQualifiedName("System.IO", "Path", "Combine")
18-
select call, "Call to 'System.IO.Path.Combine'."
19+
select call, "Call to 'System.IO.Path.Combine' may silently drop its earlier arguments."
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: queryMetadata
3+
---
4+
* Updated the `name`, `description`, and alert message of `cs/path-combine` to have more details about why it's a problem.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| PathCombine.cs:7:9:7:54 | call to method Combine | Call to 'System.IO.Path.Combine'. |
1+
| PathCombine.cs:7:9:7:54 | call to method Combine | Call to 'System.IO.Path.Combine' may silently drop its earlier arguments. |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added `PreCallGraphStep` flow model for React's `useRef` hook.
5+
* Added a `DomValueSource` that uses the `current` property off the object returned by React's `useRef` hook.

javascript/ql/lib/semmle/javascript/frameworks/React.qll

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,25 @@ private class UseStateStep extends PreCallGraphStep {
612612
}
613613
}
614614

615+
/**
616+
* Step through a `useRef` call.
617+
*
618+
* It returns an object with a single property (`current`) initialized to the initial value.
619+
*
620+
* For example:
621+
* ```js
622+
* const inputRef1 = useRef(initialValue);
623+
* ```
624+
*/
625+
private class UseRefStep extends PreCallGraphStep {
626+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
627+
exists(DataFlow::CallNode call | call = react().getAMemberCall("useRef") |
628+
pred = call.getArgument(0) and // initial state
629+
succ = call.getAPropertyRead("current")
630+
)
631+
}
632+
}
633+
615634
/**
616635
* A step through a React context object.
617636
*
@@ -785,6 +804,17 @@ private class ReactRouterLocationSource extends DOM::LocationSource::Range {
785804
}
786805
}
787806

807+
private class UseRefDomValueSource extends DOM::DomValueSource::Range {
808+
UseRefDomValueSource() {
809+
this =
810+
any(JsxAttribute attrib | attrib.getName() = "ref")
811+
.getValue()
812+
.flow()
813+
.getALocalSource()
814+
.getAPropertyRead("current")
815+
}
816+
}
817+
788818
/**
789819
* Gets a reference to a function which, if called with a React component, returns wrapped
790820
* version of that component, which we model as a direct reference to the underlying component.

rust/ast-generator/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use ungrammar::Grammar;
1515

1616
fn class_name(type_name: &str) -> String {
1717
match type_name {
18+
"Adt" => "TypeItem".to_owned(),
1819
"BinExpr" => "BinaryExpr".to_owned(),
1920
"ElseBranch" => "Expr".to_owned(),
2021
"Fn" => "Function".to_owned(),
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
class Element extends @element {
2+
string toString() { none() }
3+
}
4+
5+
class Enum extends Element, @enum { }
6+
7+
class Struct extends Element, @struct { }
8+
9+
class Union extends Element, @union { }
10+
11+
class Attr extends Element, @attr { }
12+
13+
class GenericParamList extends Element, @generic_param_list { }
14+
15+
class Name extends Element, @name { }
16+
17+
class Visibility extends Element, @visibility { }
18+
19+
class WhereClause extends Element, @where_clause { }
20+
21+
query predicate new_enum_attrs(Enum enum, int index, Attr attr) {
22+
type_item_attrs(enum, index, attr)
23+
}
24+
25+
query predicate new_enum_generic_param_lists(Enum enum, GenericParamList g) {
26+
type_item_generic_param_lists(enum, g)
27+
}
28+
29+
query predicate new_enum_names(Enum enum, Name name) { type_item_names(enum, name) }
30+
31+
query predicate new_enum_visibilities(Enum enum, Visibility visibility) {
32+
type_item_visibilities(enum, visibility)
33+
}
34+
35+
query predicate new_enum_where_clauses(Enum enum, WhereClause whereClause) {
36+
type_item_where_clauses(enum, whereClause)
37+
}
38+
39+
query predicate new_struct_attrs(Struct struct, int index, Attr attr) {
40+
type_item_attrs(struct, index, attr)
41+
}
42+
43+
query predicate new_struct_generic_param_lists(Struct struct, GenericParamList g) {
44+
type_item_generic_param_lists(struct, g)
45+
}
46+
47+
query predicate new_struct_names(Struct struct, Name name) { type_item_names(struct, name) }
48+
49+
query predicate new_struct_visibilities(Struct struct, Visibility visibility) {
50+
type_item_visibilities(struct, visibility)
51+
}
52+
53+
query predicate new_struct_where_clauses(Struct struct, WhereClause whereClause) {
54+
type_item_where_clauses(struct, whereClause)
55+
}
56+
57+
query predicate new_union_attrs(Union union, int index, Attr attr) {
58+
type_item_attrs(union, index, attr)
59+
}
60+
61+
query predicate new_union_generic_param_lists(Union union, GenericParamList g) {
62+
type_item_generic_param_lists(union, g)
63+
}
64+
65+
query predicate new_union_names(Union union, Name name) { type_item_names(union, name) }
66+
67+
query predicate new_union_visibilities(Union union, Visibility visibility) {
68+
type_item_visibilities(union, visibility)
69+
}
70+
71+
query predicate new_union_where_clauses(Union union, WhereClause whereClause) {
72+
type_item_where_clauses(union, whereClause)
73+
}

0 commit comments

Comments
 (0)