zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (ZOOKEEPER-3007) Potential NPE in ReferenceCountedACLCache#deserialize
Date Tue, 27 Mar 2018 08:22:00 GMT

    [ https://issues.apache.org/jira/browse/ZOOKEEPER-3007?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16415210#comment-16415210
] 

ASF GitHub Bot commented on ZOOKEEPER-3007:
-------------------------------------------

Github user anmolnar commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/495#discussion_r177343134
  
    --- Diff: src/java/main/org/apache/zookeeper/server/ReferenceCountedACLCache.java ---
    @@ -109,16 +109,18 @@ public synchronized void deserialize(InputArchive ia) throws IOException
{
                 }
                 List<ACL> aclList = new ArrayList<ACL>();
                 Index j = ia.startVector("acls");
    -            while (!j.done()) {
    -                ACL acl = new ACL();
    -                acl.deserialize(ia, "acl");
    -                aclList.add(acl);
    -                j.incr();
    +            if (j != null) {
    +                while (!j.done()) {
    +                    ACL acl = new ACL();
    +                    acl.deserialize(ia, "acl");
    +                    aclList.add(acl);
    +                    j.incr();
    +                }
    +                longKeyMap.put(val, aclList);
    --- End diff --
    
    +1 
    Only the inner while-loop uses the `j` variable, so nothing else should be inside the
check.


> Potential NPE in ReferenceCountedACLCache#deserialize 
> ------------------------------------------------------
>
>                 Key: ZOOKEEPER-3007
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-3007
>             Project: ZooKeeper
>          Issue Type: Bug
>    Affects Versions: 3.6.0
>            Reporter: lujie
>            Priority: Major
>
> Inspired by ZK-3006 , I develop a simple static analysis tool to find other Potential
NPE like ZK-3006. This bug is found by this tool ,and I have carefully studied it.  But i
am a newbie at here so i may be wrong, hope someone could confirm it and help me improve
this tool.
> h3. Bug describtion:
> callee BinaryInputArchive#startVector will return null:
> {code:java}
> // code placeholder
> public Index startVector(String tag) throws IOException {
>     int len = readInt(tag);
>      if (len == -1) {
>      return null;
> }
> {code}
> and caller ReferenceCountedACLCache#deserialize  call it without null check
> {code:java}
> // code placeholder
> Index j = ia.startVector("acls");
> while (!j.done()) {
>   ACL acl = new ACL();
>   acl.deserialize(ia, "acl");
> }{code}
> but all the other 14 caller of BinaryInputArchive#startVector performs null checker
like:
> {code:java}
> // code placeholder
> Index vidx1 = a_.startVector("acl");
>   if (vidx1!= null)
>      for (; !vidx1.done(); vidx1.incr()){
>      .....
>     }
>    }
> }
> {code}
> so i think we also need add null check in caller ReferenceCountedACLCache#deserialize 
just like other 14 caller
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message