Skip to content

Commit da04c8a

Browse files
authored
Remove SeparatorParameter to avoid breaking SonarSecurity (SonarSource#634)
1 parent d394b2b commit da04c8a

File tree

18 files changed

+55
-121
lines changed

18 files changed

+55
-121
lines changed

python-checks/src/main/java/org/sonar/python/checks/InfiniteRecursionCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private static Symbol findSelfParameterSymbol(FunctionDef functionDef) {
270270
return null;
271271
}
272272
Name firstParameterName = params.get(0).name();
273-
return firstParameterName.symbol();
273+
return firstParameterName != null ? firstParameterName.symbol() : null;
274274
}
275275

276276
@CheckForNull

python-checks/src/main/java/org/sonar/python/checks/MethodShouldBeStaticCheck.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,13 @@ private static boolean isUsingSelfArg(FunctionDef funcDef) {
8686
}
8787
if (params.get(0).is(Tree.Kind.TUPLE_PARAMETER)) {
8888
return false;
89-
} else if (params.get(0).is(Tree.Kind.SEPARATOR_PARAMETER)) {
90-
// star argument should not raise issue
91-
return true;
9289
}
9390
Parameter first = (Parameter) params.get(0);
9491
Name paramName = first.name();
92+
if (paramName == null) {
93+
// star argument should not raise issue
94+
return true;
95+
}
9596
SelfVisitor visitor = new SelfVisitor(paramName.name());
9697
funcDef.body().accept(visitor);
9798
return visitor.isUsingSelfArg;

python-checks/src/main/java/org/sonar/python/checks/NoReRaiseInExitCheck.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.sonar.plugins.python.api.tree.Expression;
3131
import org.sonar.plugins.python.api.tree.FunctionDef;
3232
import org.sonar.plugins.python.api.tree.HasSymbol;
33+
import org.sonar.plugins.python.api.tree.Name;
3334
import org.sonar.plugins.python.api.tree.Parameter;
3435
import org.sonar.plugins.python.api.tree.ParameterList;
3536
import org.sonar.plugins.python.api.tree.RaiseStatement;
@@ -88,7 +89,11 @@ private static Symbol extractPackedParameter(ParameterList parameterList) {
8889
return null;
8990
}
9091

91-
return parameter.name().symbol();
92+
Name name = parameter.name();
93+
if (name == null) {
94+
return null;
95+
}
96+
return name.symbol();
9297
}
9398

9499
private static Symbol extractCaughtExceptionParameter(ParameterList parameterList) {
@@ -100,7 +105,11 @@ private static Symbol extractCaughtExceptionParameter(ParameterList parameterLis
100105
}
101106

102107
Parameter parameter = regularParams.get(2);
103-
return parameter.name().symbol();
108+
Name name = parameter.name();
109+
if (name == null) {
110+
return null;
111+
}
112+
return name.symbol();
104113
}
105114

106115
@Override

python-checks/src/main/java/org/sonar/python/checks/SpecialMethodParamListCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void initialize(Context context) {
132132
}
133133

134134
// Check if the method was declared with packed arguments.
135-
if (hasPackedOrKeywordParameter(parameterList) || parameterList.stream().anyMatch(p -> p.is(Tree.Kind.SEPARATOR_PARAMETER))) {
135+
if (hasPackedOrKeywordParameter(parameterList)) {
136136
return;
137137
}
138138

python-checks/src/main/java/org/sonar/python/checks/hotspots/HardCodedCredentialsCheck.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ private void checkKeyValuePair(KeyValuePair keyValuePair, SubscriptionContext ct
142142
private void handleParameterList(ParameterList parameterList, SubscriptionContext ctx) {
143143
for (Parameter parameter : parameterList.nonTuple()) {
144144
Name parameterName = parameter.name();
145+
if (parameterName == null) {
146+
continue;
147+
}
145148
Expression defaultValue = parameter.defaultValue();
146149
String matchedCredential = matchedCredential(parameterName.name(), variablePatterns());
147150
if (matchedCredential != null && defaultValue != null && isSuspiciousStringLiteral(defaultValue)) {

python-checks/src/test/resources/checks/infiniteRecursion.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,6 @@ async def asyn5(i): # OK, await is not on "asyn5" call
341341

342342
async def asyn6(i): # Noncompliant
343343
await some_call(await asyn6(i-1), 42)
344+
345+
class A:
346+
def func(*, x, y): ...

python-frontend/src/main/java/org/sonar/plugins/python/api/tree/BaseTreeVisitor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,6 @@ public void visitParameter(Parameter tree) {
299299
scan(tree.defaultValue());
300300
}
301301

302-
@Override
303-
public void visitSeparatorParameter(SeparatorParameter parameter) {
304-
// noop
305-
}
306-
307302
@Override
308303
public void visitTypeAnnotation(TypeAnnotation tree) {
309304
scan(tree.expression());

python-frontend/src/main/java/org/sonar/plugins/python/api/tree/Parameter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public interface Parameter extends AnyParameter {
4343
@CheckForNull
4444
Token starToken();
4545

46+
@CheckForNull
4647
Name name();
4748

4849
@CheckForNull

python-frontend/src/main/java/org/sonar/plugins/python/api/tree/SeparatorParameter.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

python-frontend/src/main/java/org/sonar/plugins/python/api/tree/Tree.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ enum Kind {
137137
TRY_STMT(TryStatement.class),
138138

139139
PARAMETER(Parameter.class),
140-
SEPARATOR_PARAMETER(SeparatorParameter.class),
141140
TUPLE_PARAMETER(TupleParameter.class),
142141

143142
VARIABLE_TYPE_ANNOTATION(TypeAnnotation.class),

0 commit comments

Comments
 (0)