Skip to content

Commit 8440c7d

Browse files
committed
Adjusted codemod
1 parent 113233b commit 8440c7d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

framework/codemodder-base/src/main/java/io/codemodder/remediation/zipslip/ZipEntryStartFixStrategy.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.github.javaparser.ast.expr.MethodCallExpr;
1111
import io.codemodder.remediation.RemediationStrategy;
1212
import io.codemodder.remediation.SuccessOrReason;
13+
14+
import java.lang.invoke.MethodHandleInfo;
1315
import java.util.Optional;
1416

1517
/** Fixes ZipSlip vulnerabilities where a ZipEntry starts the data flow. */
@@ -70,8 +72,16 @@ String sanitizeZipFilename(String entryName) {
7072

7173
/** Return true if it appears to be a ZipEntry#getName() call. */
7274
static boolean match(final Node node) {
73-
return node instanceof MethodCallExpr call
74-
&& call.getScope().isPresent()
75-
&& "getName".equals(call.getNameAsString());
75+
return
76+
Optional.of(node)
77+
.map(n -> n instanceof MethodCallExpr mce ? mce : null)
78+
.filter(mce -> mce.hasScope())
79+
.filter(mce -> "getName".equals(mce.getNameAsString()))
80+
// Not already sanitized
81+
.filter(mce -> mce.getParentNode()
82+
.map(p -> p instanceof MethodCallExpr m ? m : null)
83+
.filter(m -> "sanitizeZipFilename".equals(m.getNameAsString()))
84+
.isEmpty())
85+
.isPresent();
7686
}
7787
}

0 commit comments

Comments
 (0)