]> WPIA git - gigi.git/commitdiff
FIX: race conditions by coverity.
authorFelix Dörre <felix@dogcraft.de>
Thu, 19 Feb 2015 20:19:35 +0000 (21:19 +0100)
committerFelix Dörre <felix@dogcraft.de>
Thu, 19 Feb 2015 20:19:35 +0000 (21:19 +0100)
src/org/cacert/gigi/dbObjects/Certificate.java
src/org/cacert/gigi/dbObjects/CertificateOwner.java
src/org/cacert/gigi/dbObjects/Domain.java
src/org/cacert/gigi/dbObjects/EmailAddress.java

index ced044cd8d34a102fa68875e0b9d6604d7fbfdea..9a857fe4e75d9b2640615172ee197e6937479017 100644 (file)
@@ -206,7 +206,7 @@ public class Certificate {
 
     }
 
-    public CertificateStatus getStatus() {
+    public synchronized CertificateStatus getStatus() {
         if (id == 0) {
             return CertificateStatus.DRAFT;
         }
index d7439f2ca0b60f8323b6395f6784f8b643288c37..82143db50030301a04ae6da8bdadd45b8d0f01a1 100644 (file)
@@ -41,10 +41,10 @@ public abstract class CertificateOwner implements IdCachable {
     }
 
     protected int insert() {
-        if (id != 0) {
-            throw new Error("refusing to insert");
-        }
         synchronized (User.class) {
+            if (id != 0) {
+                throw new Error("refusing to insert");
+            }
             GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO certOwners() VALUES()");
             ps.execute();
             id = ps.lastInsertId();
index c29d9b2ba00adbdede5721c04571f399bd5494c1..8efa4ee1870910f961b1476ae743d1cee7454ccb 100644 (file)
@@ -168,10 +168,10 @@ public class Domain implements IdCachable {
     }
 
     public void insert() throws GigiApiException {
-        if (id != 0) {
-            throw new GigiApiException("already inserted.");
-        }
         synchronized (Domain.class) {
+            if (id != 0) {
+                throw new GigiApiException("already inserted.");
+            }
             checkInsert(suffix);
             GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `domains` SET memid=?, domain=?");
             ps.setInt(1, owner.getId());
index b945f9eecc23028575b8d4368738ecd5d652c42e..3ca39b6d2c9d2178b6e2564965d772c1e5d804db 100644 (file)
@@ -46,10 +46,10 @@ public class EmailAddress implements IdCachable {
     }
 
     public void insert(Language l) throws GigiApiException {
-        if (id != 0) {
-            throw new IllegalStateException("already inserted.");
-        }
         try {
+            if (id != 0) {
+                throw new IllegalStateException("already inserted.");
+            }
             GigiPreparedStatement psCheck = DatabaseConnection.getInstance().prepare("SELECT 1 FROM `emails` WHERE email=? AND deleted is NULL");
             GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `emails` SET memid=?, hash=?, email=?");
             ps.setInt(1, owner.getId());