Java: fix 'matches' false branch

This commit is contained in:
Jami Cogswell
2025-03-17 18:48:44 -04:00
parent 49d37c517d
commit 0d2e9ae469
2 changed files with 24 additions and 6 deletions

View File

@@ -684,16 +684,33 @@ public class Test {
// branch = false
{
String source = (String) source();
if (source.matches(".*[\\./\\\\].*")) {
sink(source); // $ hasTaintFlow
} else {
sink(source); // Safe
}
}
{
String source = (String) source();
if (source.matches(".+[\\./\\\\].+")) {
sink(source); // $ hasTaintFlow
} else {
sink(source); // Safe
}
}
{
String source = (String) source();
// does not match whole string
if (source.matches("[\\./\\\\]+")) {
sink(source); // $ hasTaintFlow
} else {
sink(source); // $ Safe
sink(source); // $ hasTaintFlow
}
}
{
String source = (String) source();
// not a complete sanitizer since it doesn't protect against absolute path injection
if (source.matches("[\\.]+")) {
if (source.matches(".+[\\.].+")) {
sink(source); // $ hasTaintFlow
} else {
sink(source); // $ hasTaintFlow