Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nimakarimipour committed Dec 20, 2024
1 parent 07ed77a commit e9d4fe5
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public Set<Fix> visitMethodInvocation(MethodInvocationTree node, FoundRequired p
return answer(polyFixes);
}
}
if (CollectionHandler.isGenericToArrayMethod(calledMethod, types) || CollectionHandler.isToArrayMethod(calledMethod, types)) {
if (CollectionHandler.isGenericToArrayMethod(calledMethod, types)
|| CollectionHandler.isToArrayMethod(calledMethod, types)) {
return answer(node.accept(collectionFixVisitor, pair));
}
if (isGenericMethod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ public Set<Fix> visitMethodInvocation(MethodInvocationTree node, FoundRequired p
for (Type.TypeVar typeVar : effectiveTypes) {
for (int i = 0; i < node.getArguments().size(); i++) {
AnnotatedTypeMirror requiredParam = paramsAnnotatedTypeMirrors.get(i).deepCopy(true);
requiredParam =
(requiredParam instanceof AnnotatedTypeMirror.AnnotatedArrayType)
? ((AnnotatedTypeMirror.AnnotatedArrayType) requiredParam).getComponentType()
: requiredParam;
Type paramType =
calledMethod.isVarArgs()
(calledMethod.isVarArgs() && i == node.getArguments().size() - 1)
? ((Type.ArrayType) calledMethod.getParameters().get(0).type).getComponentType()
: calledMethod.getParameters().get(i).type;
boolean changed = updateAnnotatedTypeMirror(requiredParam, paramType, typeVar);
Expand Down
43 changes: 43 additions & 0 deletions tests/collectionhandling/expected-output.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,49 @@
}
}
]
},
{
"path": "/home/nima/Developer/git/UCRTaintingChecker/tests/collectionhandling/foo/bar/Foo.java",
"messageKey": "assignment",
"offset": 937,
"index": 2,
"region": {
"symbol": "arraysAsListGenericTest()",
"class": "foo.bar.Foo"
},
"fixes": [
{
"annotation": "untainted",
"location": {
"path": "/home/nima/Developer/git/UCRTaintingChecker/tests/collectionhandling/foo/bar/Foo.java",
"varName": "array",
"type-variable-position": [
[
0
]
],
"method": "arraysAsListGenericTest()",
"kind": "LOCAL_VARIABLE",
"class": "foo.bar.Foo"
}
},
{
"annotation": "untainted",
"location": {
"path": "/home/nima/Developer/git/UCRTaintingChecker/tests/collectionhandling/foo/bar/Foo.java",
"varName": "c1",
"type-variable-position": [
[
1,
0
]
],
"method": "arraysAsListGenericTest()",
"kind": "LOCAL_VARIABLE",
"class": "foo.bar.Foo"
}
}
]
}
]
}
10 changes: 9 additions & 1 deletion tests/collectionhandling/foo/bar/Foo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import edu.ucr.cs.riple.taint.ucrtainting.qual.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.LinkedList;

public class Foo {

Expand All @@ -24,4 +24,12 @@ void refraingFromApplyingUnannotatedCodeHandlerForToArrayMethod() {
// :: error: assignment
@RUntainted Object[] array = c1.toArray();
}

void arraysAsListGenericTest() {
LinkedList<String> c1 = new LinkedList<>();
c1.addFirst("x");
Object[] array = c1.toArray();
// :: error: assignment
List<@RUntainted Object> c2 = java.util.Arrays.asList(array);
}
}
1 change: 1 addition & 0 deletions tests/templatetest/foo/bar/Test.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package foo.bar;

import edu.ucr.cs.riple.taint.ucrtainting.qual.*;
import java.io.*;
import java.lang.annotation.*;
import java.util.*;
import javax.servlet.http.*;
Expand Down
Binary file added thirdparty/bin/main/org/thirdparty/Foo.class
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The "qual" directory contains a typechecker's type qualifiers, which are
represented by Java annotations.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit e9d4fe5

Please sign in to comment.