Add a null check to method HttpStaticFileServerHandler.sendListing (#10040)
Motivation: java.io.File.listFiles() may return null and cause a unexpected NPE. Modification: Extract a local variable from the return value of File.listFiles() and do a null check. Result: Fix the potential NPE.
This commit is contained in:
parent
dcd62c2598
commit
125cd9552d
@ -286,21 +286,24 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
|
||||
.append("<ul>")
|
||||
.append("<li><a href=\"../\">..</a></li>\r\n");
|
||||
|
||||
for (File f: dir.listFiles()) {
|
||||
if (f.isHidden() || !f.canRead()) {
|
||||
continue;
|
||||
}
|
||||
File[] files = dir.listFiles();
|
||||
if (files != null) {
|
||||
for (File f: files) {
|
||||
if (f.isHidden() || !f.canRead()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = f.getName();
|
||||
if (!ALLOWED_FILE_NAME.matcher(name).matches()) {
|
||||
continue;
|
||||
}
|
||||
String name = f.getName();
|
||||
if (!ALLOWED_FILE_NAME.matcher(name).matches()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
buf.append("<li><a href=\"")
|
||||
.append(name)
|
||||
.append("\">")
|
||||
.append(name)
|
||||
.append("</a></li>\r\n");
|
||||
buf.append("<li><a href=\"")
|
||||
.append(name)
|
||||
.append("\">")
|
||||
.append(name)
|
||||
.append("</a></li>\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
buf.append("</ul></body></html>\r\n");
|
||||
|
Loading…
Reference in New Issue
Block a user