Skip to content

Commit 0262105

Browse files
author
Federico Fissore
committed
Several File.list() calls missed check for null return value. Fixed
1 parent 0b4a4fb commit 0262105

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

app/src/processing/app/Base.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -2604,12 +2604,15 @@ static public void copyDir(File sourceDir,
26042604
File targetDir) throws IOException {
26052605
targetDir.mkdirs();
26062606
String files[] = sourceDir.list();
2607-
for (int i = 0; i < files.length; i++) {
2607+
if (files == null) {
2608+
throw new IOException("Unable to list files from " + sourceDir);
2609+
}
2610+
for (String file : files) {
26082611
// Ignore dot files (.DS_Store), dot folders (.svn) while copying
2609-
if (files[i].charAt(0) == '.') continue;
2612+
if (file.charAt(0) == '.') continue;
26102613
//if (files[i].equals(".") || files[i].equals("..")) continue;
2611-
File source = new File(sourceDir, files[i]);
2612-
File target = new File(targetDir, files[i]);
2614+
File source = new File(sourceDir, file);
2615+
File target = new File(targetDir, file);
26132616
if (source.isDirectory()) {
26142617
//target.mkdirs();
26152618
copyDir(source, target);

app/src/processing/app/tools/Archiver.java

+3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ public void run() {
150150
public void buildZip(File dir, String sofar,
151151
ZipOutputStream zos) throws IOException {
152152
String files[] = dir.list();
153+
if (files == null) {
154+
throw new IOException("Unable to list files from " + dir);
155+
}
153156
for (int i = 0; i < files.length; i++) {
154157
if (files[i].equals(".") ||
155158
files[i].equals("..")) continue;

arduino-core/src/processing/app/BaseNoGui.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -956,14 +956,18 @@ static public void removeDescendants(File dir) {
956956
if (!dir.exists()) return;
957957

958958
String files[] = dir.list();
959-
for (int i = 0; i < files.length; i++) {
960-
if (files[i].equals(".") || files[i].equals("..")) continue;
961-
File dead = new File(dir, files[i]);
959+
if (files == null) {
960+
return;
961+
}
962+
963+
for (String file : files) {
964+
if (file.equals(".") || file.equals("..")) continue;
965+
File dead = new File(dir, file);
962966
if (!dead.isDirectory()) {
963967
if (!PreferencesData.getBoolean("compiler.save_build_files")) {
964968
if (!dead.delete()) {
965969
// temporarily disabled
966-
System.err.println(I18n.format(_("Could not delete {0}"), dead));
970+
System.err.println(I18n.format(_("Could not delete {0}"), dead));
967971
}
968972
}
969973
} else {

arduino-core/src/processing/app/SketchData.java

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ protected void load() throws IOException {
9595

9696
// get list of files in the sketch folder
9797
String list[] = folder.list();
98+
if (list == null) {
99+
throw new IOException("Unable to list files from " + folder);
100+
}
98101

99102
// reset these because load() may be called after an
100103
// external editor event. (fix for 0099)

arduino-core/src/processing/app/debug/Compiler.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,13 @@ protected void cleanup(boolean force, File tempBuildFolder) {
277277
// used. Keep everything else, which might be reusable
278278
if (tempBuildFolder.exists()) {
279279
String files[] = tempBuildFolder.list();
280-
for (String file : files) {
281-
if (file.endsWith(".c") || file.endsWith(".cpp") || file.endsWith(".s")) {
282-
File deleteMe = new File(tempBuildFolder, file);
283-
if (!deleteMe.delete()) {
284-
System.err.println("Could not delete " + deleteMe);
280+
if (files != null) {
281+
for (String file : files) {
282+
if (file.endsWith(".c") || file.endsWith(".cpp") || file.endsWith(".s")) {
283+
File deleteMe = new File(tempBuildFolder, file);
284+
if (!deleteMe.delete()) {
285+
System.err.println("Could not delete " + deleteMe);
286+
}
285287
}
286288
}
287289
}

0 commit comments

Comments
 (0)