1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-03-30 22:19:17 +02:00

check the return value of rmtree in java stdapi_fs_delete_dir

This commit is contained in:
Tim W 2022-01-12 12:38:37 +00:00
parent e0dae30a95
commit 670fd8360c

@ -17,7 +17,9 @@ public class stdapi_fs_delete_dir implements Command {
throw new IOException("Cannot delete symbolic link " + file.getCanonicalPath()); throw new IOException("Cannot delete symbolic link " + file.getCanonicalPath());
} }
} else if (file.isDirectory()) { } else if (file.isDirectory()) {
rmtree(file); if (!rmtree(file)) {
throw new IOException("Cannot delete " + file.getCanonicalPath());
}
} else { } else {
throw new IOException("Directory not found: " + path); throw new IOException("Directory not found: " + path);
} }
@ -35,17 +37,18 @@ public class stdapi_fs_delete_dir implements Command {
return !canon.getCanonicalFile().equals(canon.getAbsoluteFile()); return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
} }
private void rmtree(File file) throws IOException { private boolean rmtree(File file) throws IOException {
boolean ret = true;
for (File subFile : file.listFiles()) { for (File subFile : file.listFiles()) {
if (isSymlink(subFile)) { if (isSymlink(subFile)) {
subFile.delete(); ret = ret && subFile.delete();
} else if (subFile.isDirectory()) { } else if (subFile.isDirectory()) {
rmtree(subFile); ret = ret && rmtree(subFile);
} else { } else {
subFile.delete(); ret = ret && subFile.delete();
} }
} }
file.delete(); ret = ret && file.delete();
return; return ret;
} }
} }