From e9d4fe5bf98f6f41720e542a8d22d7163647848a Mon Sep 17 00:00:00 2001 From: Nima Karimipour Date: Thu, 19 Dec 2024 20:31:15 -0800 Subject: [PATCH] fix bug --- .../serialization/visitors/FixComputer.java | 3 +- .../visitors/GenericMethodFixVisitor.java | 6 ++- tests/collectionhandling/expected-output.json | 43 ++++++++++++++++++ tests/collectionhandling/foo/bar/Foo.java | 10 +++- tests/templatetest/foo/bar/Test.java | 1 + thirdparty/bin/main/org/thirdparty/Foo.class | Bin 0 -> 554 bytes .../cs/riple/taint/ucrtainting/qual/README | 2 + .../taint/ucrtainting/qual/RPolyTainted.class | Bin 0 -> 604 bytes .../ucrtainting/qual/RPossiblyValidated.class | Bin 0 -> 666 bytes .../taint/ucrtainting/qual/RTainted.class | Bin 0 -> 604 bytes .../riple/taint/ucrtainting/qual/RThis.class | Bin 0 -> 582 bytes .../taint/ucrtainting/qual/RUntainted.class | Bin 0 -> 738 bytes 12 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 thirdparty/bin/main/org/thirdparty/Foo.class create mode 100644 ucrtainting-checker-qual/bin/main/edu/ucr/cs/riple/taint/ucrtainting/qual/README create mode 100644 ucrtainting-checker-qual/bin/main/edu/ucr/cs/riple/taint/ucrtainting/qual/RPolyTainted.class create mode 100644 ucrtainting-checker-qual/bin/main/edu/ucr/cs/riple/taint/ucrtainting/qual/RPossiblyValidated.class create mode 100644 ucrtainting-checker-qual/bin/main/edu/ucr/cs/riple/taint/ucrtainting/qual/RTainted.class create mode 100644 ucrtainting-checker-qual/bin/main/edu/ucr/cs/riple/taint/ucrtainting/qual/RThis.class create mode 100644 ucrtainting-checker-qual/bin/main/edu/ucr/cs/riple/taint/ucrtainting/qual/RUntainted.class diff --git a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/FixComputer.java b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/FixComputer.java index 7eced55b..f5923d4a 100644 --- a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/FixComputer.java +++ b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/FixComputer.java @@ -149,7 +149,8 @@ public Set 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) { diff --git a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/GenericMethodFixVisitor.java b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/GenericMethodFixVisitor.java index 8cd44599..73552c16 100644 --- a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/GenericMethodFixVisitor.java +++ b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/GenericMethodFixVisitor.java @@ -72,8 +72,12 @@ public Set 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); diff --git a/tests/collectionhandling/expected-output.json b/tests/collectionhandling/expected-output.json index 7be98e74..55425952 100644 --- a/tests/collectionhandling/expected-output.json +++ b/tests/collectionhandling/expected-output.json @@ -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" + } + } + ] } ] } diff --git a/tests/collectionhandling/foo/bar/Foo.java b/tests/collectionhandling/foo/bar/Foo.java index 4ef148b7..7f1a99f2 100644 --- a/tests/collectionhandling/foo/bar/Foo.java +++ b/tests/collectionhandling/foo/bar/Foo.java @@ -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 { @@ -24,4 +24,12 @@ void refraingFromApplyingUnannotatedCodeHandlerForToArrayMethod() { // :: error: assignment @RUntainted Object[] array = c1.toArray(); } + + void arraysAsListGenericTest() { + LinkedList c1 = new LinkedList<>(); + c1.addFirst("x"); + Object[] array = c1.toArray(); + // :: error: assignment + List<@RUntainted Object> c2 = java.util.Arrays.asList(array); + } } diff --git a/tests/templatetest/foo/bar/Test.java b/tests/templatetest/foo/bar/Test.java index 4e4e1f38..88b522c6 100644 --- a/tests/templatetest/foo/bar/Test.java +++ b/tests/templatetest/foo/bar/Test.java @@ -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.*; diff --git a/thirdparty/bin/main/org/thirdparty/Foo.class b/thirdparty/bin/main/org/thirdparty/Foo.class new file mode 100644 index 0000000000000000000000000000000000000000..3818131089ba48b7f185c883fa6729fe9a4cf274 GIT binary patch literal 554 zcmZvZy-or_6ot<$|A-=p7z-2a(86u3glu9ARHy}net^w7WZfm>tO;+Wm5GH9;6oYD zESP}U+@Evjes|{1*Z0RKfGZpo;0V-X9k}LE>FHc*vv7NHTtHS}e`baEj+0cSCW&R`2MR3QCYjZAVImSJ{T_Sd zv;tc}7N@31_hw+8BbsOj0(;e|^Uo8V^~kMO7TBH62`FU-Z^M+?p^7rT{@@QPzuD*! z3%ua&D!i=u0^8Fip|UMXnYll`??>bo3`c!pQXzb(`%ibbJa1(T>y@BV^Fu!nIIAYM zC3Ty0mu%Cj9=#^ED<^1dhjXKs*nZpS8@9(Z4Ot$1T>ZD7-(Hpv1O#UI%<{JYa`48n ifO*b`$YX)?BKMaF%UHpxgOA7&iYU3ThILoc*!Tj947e5m literal 0 HcmV?d00001 diff --git a/ucrtainting-checker-qual/bin/main/edu/ucr/cs/riple/taint/ucrtainting/qual/RPossiblyValidated.class b/ucrtainting-checker-qual/bin/main/edu/ucr/cs/riple/taint/ucrtainting/qual/RPossiblyValidated.class new file mode 100644 index 0000000000000000000000000000000000000000..e1f79320dc002a9301f835a35ec5025e4ff16ea2 GIT binary patch literal 666 zcma))O-~y!5Qblej|B=8C?DzpQ8*xa!Q7DG6p2Nu6d>9xNGONOaVEjw?1I+@<*#w* z58y{3W>cw))JSmH@$1>g?~FBmd42u^;1C-TY63^p4Kipabs?R(wq-4APUA#CHgeaO`iAr!xt>!4ddl6Mtkh_XtEnaI|{zz=?!4l7Qf{m>3VHlmQB57fXxbuX*qX_@j)o z80A8uhfZJKyf=Nx^yBmG9RRN3(1R3%OYA!Cq~UVPjhblWR;b7()B>oe&tII-JO~pW zyB@4FC=A6+a4o3W=nPR>4>lN_ELjmnu@zRu5ikEj2H95ZjKmwIkwNZfIVXb`wC}=d z-DhyT+7b%WM@!1{)qP)M5-^-kkVKjAvFSgzTQo1ffX#AHuKS@MFeukz)8}%4a)hR5 z#28;=GvZ6MSVIMS!fAU?D^Wd#rW)N+6-Ew{xcpx;TCQU$Poq~VGGMSqCrw`hAO+r{ kW?+-EnaMKzu9z2n_CMFzqWLp^h-4c3|8orX!`&K@UmEjHOiMzgbL+#>Te)y X!WL|&@EHmSRoF?xF6{l3n1uarx5cg- literal 0 HcmV?d00001 diff --git a/ucrtainting-checker-qual/bin/main/edu/ucr/cs/riple/taint/ucrtainting/qual/RUntainted.class b/ucrtainting-checker-qual/bin/main/edu/ucr/cs/riple/taint/ucrtainting/qual/RUntainted.class new file mode 100644 index 0000000000000000000000000000000000000000..fa8625693d6d07e560aa0360441a9837f93763e8 GIT binary patch literal 738 zcma)4%We}f6g^HKQwsD+TUa0-i!N)y2B}n)A~CJ1rfrx^Dj^ogac+WJ$1WaEtNa=Z zK7fxx+?iHn6NxNrADw&7xt6bg|M~d~zy~}}&=7b}{Zf`XNL|QaZY;^DjEfaj1LKDB zN2#pLx~?XupI}~K?MmG$X%&|*dRL@lf<=K>6IMCrql(5m+586umOH)-nvRSmfz?Uq zUgZ>ck(Dl*5nYePuFA=S;2Q<$-=F&B{$#wkF@Qr z(PK6wS@%3YIZFjzPPgPL3@Nhm?euzTsk&f3z9AMZs)WiN8p#emZeS~Cx@?ThMB$Ct{QzPf*}{h1nm<_};7 zhQg5#EfXmyTX64pGnpR@r^ZzSTI}T6$@%fFfWRED1^$ab14+Fv;SryQ%r5i!nCnjn ePqBj43Vua{u!i+&+rZ{MB{ZI4>j4wCvGW%Xz2lew literal 0 HcmV?d00001