zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject zookeeper git commit: ZOOKEEPER-3007: Potential NPE in ReferenceCountedACLCache#deserialize
Date Thu, 26 Apr 2018 22:22:18 GMT
Repository: zookeeper
Updated Branches:
  refs/heads/master 79627c6e0 -> 2c0168ad3


ZOOKEEPER-3007: Potential NPE in ReferenceCountedACLCache#deserialize

LJ1043041006 found a potential NPE in ZK

Author: gongleigl.gong <gongleigl.gong@qunar.com>
Author: brettkk <1099446733@qq.com>

Reviewers: phunt@apache.org

Closes #495 from brettKK/master and squashes the following commits:

7eb9e1c9b [gongleigl.gong] fix RTE message in ReferenceCountedACLCache class
0b858826d [gongleigl.gong] del logger error and fix error message
a12b13ff7 [brettkk] fix format
f7da9b9fa [brettkk] change ZOOK3007 to compare with apache master
cf9fb5f9a [brettkk] recover code
c4db5e25d [brettkk] recover zookeeper master same with apache:master
700dfb7f4 [gongleigl.gong] fix NPE bug
7d8d5230c [gongleigl.gong] d

Change-Id: I012c242e8566fcd54c1ebde1a30ec785b6aa31b0


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/2c0168ad
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/2c0168ad
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/2c0168ad

Branch: refs/heads/master
Commit: 2c0168ad37b529447ac8cb1bf866d014f8a97981
Parents: 79627c6
Author: gongleigl.gong <gongleigl.gong@qunar.com>
Authored: Thu Apr 26 15:21:06 2018 -0700
Committer: Patrick Hunt <phunt@apache.org>
Committed: Thu Apr 26 15:21:36 2018 -0700

----------------------------------------------------------------------
 .../server/ReferenceCountedACLCache.java        |  3 ++
 .../server/ReferenceCountedACLCacheTest.java    | 29 +++++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/2c0168ad/src/java/main/org/apache/zookeeper/server/ReferenceCountedACLCache.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/ReferenceCountedACLCache.java b/src/java/main/org/apache/zookeeper/server/ReferenceCountedACLCache.java
index 486b845..384d23a 100644
--- a/src/java/main/org/apache/zookeeper/server/ReferenceCountedACLCache.java
+++ b/src/java/main/org/apache/zookeeper/server/ReferenceCountedACLCache.java
@@ -109,6 +109,9 @@ public class ReferenceCountedACLCache {
             }
             List<ACL> aclList = new ArrayList<ACL>();
             Index j = ia.startVector("acls");
+            if (j == null) {
+                throw new RuntimeException("Incorrent format of InputArchive when deserialize
DataTree - missing acls");
+            }
             while (!j.done()) {
                 ACL acl = new ACL();
                 acl.deserialize(ia, "acl");

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/2c0168ad/src/java/test/org/apache/zookeeper/server/ReferenceCountedACLCacheTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/ReferenceCountedACLCacheTest.java b/src/java/test/org/apache/zookeeper/server/ReferenceCountedACLCacheTest.java
index 076657b..795472f 100644
--- a/src/java/test/org/apache/zookeeper/server/ReferenceCountedACLCacheTest.java
+++ b/src/java/test/org/apache/zookeeper/server/ReferenceCountedACLCacheTest.java
@@ -20,6 +20,8 @@ package org.apache.zookeeper.server;
 
 import org.apache.jute.BinaryInputArchive;
 import org.apache.jute.BinaryOutputArchive;
+import org.apache.jute.InputArchive;
+import org.apache.jute.OutputArchive;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Id;
@@ -188,10 +190,35 @@ public class ReferenceCountedACLCacheTest {
         callAddUsageNTimes(deserializedCache, aclId3, 3);
         callAddUsageNTimes(deserializedCache, aclId4, 4);
         callAddUsageNTimes(deserializedCache, aclId5, 5);
-
         assertCachesEqual(cache, deserializedCache);
     }
 
+    @Test
+    public void testNPEInDeserialize() throws IOException {
+        ReferenceCountedACLCache serializeCache = new ReferenceCountedACLCache(){
+            @Override
+            public synchronized void serialize(OutputArchive oa) throws IOException {
+                oa.writeInt(1, "map");
+                oa.writeLong(1, "long");
+                oa.startVector(null, "acls");
+                oa.endVector(null, "acls");
+            }
+        };
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        BinaryOutputArchive archive = BinaryOutputArchive.getArchive(baos);
+        serializeCache.serialize(archive);
+        BinaryInputArchive inArchive = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
+        ReferenceCountedACLCache deserializedCache = new ReferenceCountedACLCache();
+        try {
+            deserializedCache.deserialize(inArchive);
+        } catch (NullPointerException e){
+            fail("should not throw NPE while do deserialized");
+        } catch (RuntimeException e) {
+            // do nothing.
+        }
+    }
+
+
     private void assertCachesEqual(ReferenceCountedACLCache expected, ReferenceCountedACLCache
actual){
         assertEquals(expected.aclIndex, actual.aclIndex);
         assertEquals(expected.aclKeyMap, actual.aclKeyMap);


Mime
View raw message