Skip to content

Commit d203ffc

Browse files
author
Gary Gregory
committed
Reimplement FilenameUtils.requireNonNullChars() to reuse JRE method.
This is simpler; bonus: no repeated calls to charAt().
1 parent 9ac204d commit d203ffc

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/main/java/org/apache/commons/io/FilenameUtils.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -994,18 +994,16 @@ public static String getName(final String fileName) {
994994
}
995995

996996
/**
997-
* Check the input for null bytes, a sign of unsanitized data being passed to to file level functions.
997+
* Checks the input for null bytes, a sign of unsanitized data being passed to to file level functions.
998998
*
999999
* This may be used for poison byte attacks.
1000+
*
10001001
* @param path the path to check
10011002
*/
10021003
private static void requireNonNullChars(final String path) {
1003-
final int len = path.length();
1004-
for (int i = 0; i < len; i++) {
1005-
if (path.charAt(i) == 0) {
1006-
throw new IllegalArgumentException("Null byte present in file/path name. There are no " +
1007-
"known legitimate use cases for such data, but several injection attacks may use it");
1008-
}
1004+
if (path.indexOf(0) >= 0) {
1005+
throw new IllegalArgumentException("Null byte present in file/path name. There are no "
1006+
+ "known legitimate use cases for such data, but several injection attacks may use it");
10091007
}
10101008
}
10111009

0 commit comments

Comments
 (0)