Fix unsafe global config access 85/82185/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 21 May 2019 11:27:02 +0000 (13:27 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 21 May 2019 11:27:02 +0000 (13:27 +0200)
Current global config is a volatile variable, hence it must be
acquired into a local variable for proper nullness checks --
otherwise it is open to TOCTOU race conditions leading to NPEs.

Change-Id: I9316b3ed976575726da7a065668c507e15fe0ddf
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeAuthProviderImpl.java

index 54cd9ac7c98c09dd9525d4c9d71cc7770f1f5b19..63c25482e9c2027fd967b6b9357e7327b9f52521 100644 (file)
@@ -233,7 +233,6 @@ public class CallHomeAuthProviderImpl implements CallHomeAuthorizationProvider,
     }
 
     private static class GlobalConfig implements DataTreeChangeListener<Global> {
-
         private volatile Global current = null;
 
         @Override
@@ -244,15 +243,14 @@ public class CallHomeAuthProviderImpl implements CallHomeAuthorizationProvider,
         }
 
         boolean allowedUnknownKeys() {
-            if (current == null) {
-                return false;
-            }
+            final Global local = current;
             // Deal with null values.
-            return Boolean.TRUE.equals(current.isAcceptAllSshKeys());
+            return local != null && Boolean.TRUE.equals(local.isAcceptAllSshKeys());
         }
 
         Credentials getCredentials() {
-            return current != null ? current.getCredentials() : null;
+            final Global local = current;
+            return local != null ? local.getCredentials() : null;
         }
     }
 }