-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZOOKEEPER-3007:Potential NPE in ReferenceCountedACLCache#deserialize #495
Conversation
acl.deserialize(ia, "acl"); | ||
aclList.add(acl); | ||
j.incr(); | ||
if (j != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- can we have a more elegant way to process this NPE ?
- BTW. incorrect commit message.
git commit --amend -m "your new message"
to modify it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aclList.add(acl); | ||
j.incr(); | ||
} | ||
longKeyMap.put(val, aclList); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move code at line 119~123 out of null-checker, because it may cause endless loop due to i > 0 may always hold
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Only the inner while-loop uses the j
variable, so nothing else should be inside the check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brettKK Thanks for the fix. It'd be nice to add at least a unit test to cover the issue.
I think adding the check alone is not enough here. Looking at the serialize()
method, if map field is greater than 0, both long
and acls
fields must also be present.
In other words, in deserialize()
if (i>0) then both long
and acls
are mandatory.
As a consequence the else branch of the check should also be implemented and an exception should be thrown indicating that the archive cannot be deserialised, because the format is incorrect.
Does it make sense?
@LJ1043041006 Looking good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have run the test, +1 LGTM
Can we close it??? |
@@ -109,6 +109,10 @@ public synchronized void deserialize(InputArchive ia) throws IOException { | |||
} | |||
List<ACL> aclList = new ArrayList<ACL>(); | |||
Index j = ia.startVector("acls"); | |||
if (j == null) { | |||
LOG.error("ERROR: incorrent format of InputArchive" + ia); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need an ERROR in the text here or on the next line. It's already LOG'd as an error. Same for the next line - it's a RTE.
Also you need a space "... of InputArchive" -> ".... of InputArchive " (notice space at the end. Otw the text of ia is just appended w/o the space. Also notice that ia doesn't have a toString, so I'm not sure how helpful that is.... it's fine to leave I guess.
I ran out of time to answer this question, perhaps you can tell me - what happens when the RTE is thrown? Is the caller handling it appropriately/reasonably, or are we just pushing the problem somewhere else? |
@phunt : |
Understood on throwing the exception (1&2). I'm interested in 3 - when it is thrown is it handled correctly or some unexpected sideeffect. If we're going to try to fix we should really ensure we fix it. |
@phunt |
Ok, that (call site analysis) makes sense. I'm afraid I was unclear, when I said "You don't need an ERROR in the text here or on the next line." What I mean is that the text string should not start with "ERROR" given the error string is in an exception and the logging (from one of the callers) will determine the severity to assign. As such my recommendation would be something like:
Notice: 1) the removal of "ERROR" and 2) the addition of "missing acls" in order to give the person diagnosing the problem a bit more insight (otw they have to find the source line in order to get more insight into what they formatting issue might be). If you clear this up (this one line) I think we should be good for commit. Thanks! |
Seems that unit test error is not caused by this patch? |
LJ1043041006 found a potential NPE in ZK Author: gongleigl.gong <[email protected]> Author: brettkk <[email protected]> Reviewers: [email protected] Closes #495 from brettKK/master and squashes the following commits: 7eb9e1c [gongleigl.gong] fix RTE message in ReferenceCountedACLCache class 0b85882 [gongleigl.gong] del logger error and fix error message a12b13f [brettkk] fix format f7da9b9 [brettkk] change ZOOK3007 to compare with apache master cf9fb5f [brettkk] recover code c4db5e2 [brettkk] recover zookeeper master same with apache:master 700dfb7 [gongleigl.gong] fix NPE bug 7d8d523 [gongleigl.gong] d Change-Id: I012c242e8566fcd54c1ebde1a30ec785b6aa31b0 (cherry picked from commit 2c0168a) Signed-off-by: Patrick Hunt <[email protected]>
LJ1043041006 found a potential NPE in ZK Author: gongleigl.gong <[email protected]> Author: brettkk <[email protected]> Reviewers: [email protected] Closes #495 from brettKK/master and squashes the following commits: 7eb9e1c [gongleigl.gong] fix RTE message in ReferenceCountedACLCache class 0b85882 [gongleigl.gong] del logger error and fix error message a12b13f [brettkk] fix format f7da9b9 [brettkk] change ZOOK3007 to compare with apache master cf9fb5f [brettkk] recover code c4db5e2 [brettkk] recover zookeeper master same with apache:master 700dfb7 [gongleigl.gong] fix NPE bug 7d8d523 [gongleigl.gong] d Change-Id: I012c242e8566fcd54c1ebde1a30ec785b6aa31b0 (cherry picked from commit 2c0168a) Signed-off-by: Patrick Hunt <[email protected]>
LJ1043041006 found a potential NPE in ZK Author: gongleigl.gong <[email protected]> Author: brettkk <[email protected]> Reviewers: [email protected] Closes apache#495 from brettKK/master and squashes the following commits: 7eb9e1c [gongleigl.gong] fix RTE message in ReferenceCountedACLCache class 0b85882 [gongleigl.gong] del logger error and fix error message a12b13f [brettkk] fix format f7da9b9 [brettkk] change ZOOK3007 to compare with apache master cf9fb5f [brettkk] recover code c4db5e2 [brettkk] recover zookeeper master same with apache:master 700dfb7 [gongleigl.gong] fix NPE bug 7d8d523 [gongleigl.gong] d Change-Id: I012c242e8566fcd54c1ebde1a30ec785b6aa31b0
LJ1043041006 found a potential NPE in ZK Author: gongleigl.gong <[email protected]> Author: brettkk <[email protected]> Reviewers: [email protected] Closes apache#495 from brettKK/master and squashes the following commits: 7eb9e1c [gongleigl.gong] fix RTE message in ReferenceCountedACLCache class 0b85882 [gongleigl.gong] del logger error and fix error message a12b13f [brettkk] fix format f7da9b9 [brettkk] change ZOOK3007 to compare with apache master cf9fb5f [brettkk] recover code c4db5e2 [brettkk] recover zookeeper master same with apache:master 700dfb7 [gongleigl.gong] fix NPE bug 7d8d523 [gongleigl.gong] d Change-Id: I012c242e8566fcd54c1ebde1a30ec785b6aa31b0
@LJ1043041006 found a potential NPE in ZK
callee BinaryInputArchive#startVector will return null:
and caller ReferenceCountedACLCache#deserialize call it without null check