]> WPIA git - gigi.git/commitdiff
fix: Possible NPE if the profile configuration could not be read
authorBenny Baumann <BenBE1987@gmx.net>
Sun, 31 Jul 2016 12:16:24 +0000 (14:16 +0200)
committerBenny Baumann <BenBE1987@gmx.net>
Sun, 31 Jul 2016 15:03:14 +0000 (17:03 +0200)
Change-Id: Id21ffcd5bcf692ceed1d1896221c89357ab61696

src/org/cacert/gigi/dbObjects/CACertificate.java
src/org/cacert/gigi/dbObjects/CertificateProfile.java

index 41401b6ddab883b84e10180f766bf1492882d212..3e8af82274704ffe728f9463c8d18004b80c1fe1 100644 (file)
@@ -89,7 +89,11 @@ public class CACertificate implements IdCachable {
         CertificateFactory xf = CertificateFactory.getInstance("X509");
         HashMap<X500Principal, X509Certificate> map = new HashMap<>();
         HashMap<X500Principal, String> names = new HashMap<>();
-        for (File f : scandir.listFiles()) {
+        File[] scandirfiles = scandir.listFiles();
+        if (null == scandirfiles) {
+            scandirfiles = new File[0];
+        }
+        for (File f : scandirfiles) {
             X509Certificate cert = (X509Certificate) xf.generateCertificate(new FileInputStream(f));
             X500Principal princip = cert.getSubjectX500Principal();
             map.put(princip, cert);
index 5704497986388f70123d5bf7230839bed85fde0d..afcc019c417b172308d5092921df3e020e7879c5 100644 (file)
@@ -180,7 +180,13 @@ public class CertificateProfile implements IdCachable {
         final HashMap<String, CertificateProfile> myName = new HashMap<String, CertificateProfile>();
         final HashMap<Integer, CertificateProfile> myId = new HashMap<Integer, CertificateProfile>();
 
-        for (File f : new File("config/profiles").listFiles()) {
+        File profiledir = new File("config/profiles");
+        File[] profilelist = profiledir.listFiles();
+        if (null == profilelist) {
+            throw new Error("Unable to list available profiles from " + profiledir.getName());
+        }
+
+        for (File f : profilelist) {
             Properties p = new Properties();
             try (FileInputStream inStream = new FileInputStream(f)) {
                 p.load(inStream);