Skip to content
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-3008: Potential NPE in SaslQuorumAuthLearner#authenticate and SaslQuorumAuthServer#authenticate #496

Open
wants to merge 70 commits into
base: master
Choose a base branch
from

Conversation

brettKK
Copy link

@brettKK brettKK commented Mar 28, 2018

@LJ1043041006 found a potential NPE in ZK

callee :SecurityUtils#createSaslClient will return null while encounter exception

// code placeholder
catch (Exception e) {
  LOG.error("Exception while trying to create SASL client", e);
  return null;
}

but its caller has no null check just like:

and caller SaslQuorumAuthLearner#authenticate call it without null check

// code placeholder
sc = SecurityUtils.createSaslClient();
if (sc.hasInitialResponse()) {
   responseToken = createSaslToken(new byte[0], sc, learnerLogin);
}

@@ -94,7 +94,7 @@ public void authenticate(Socket sock, String hostName) throws IOException {
principalConfig,
QuorumAuth.QUORUM_SERVER_PROTOCOL_NAME,
QuorumAuth.QUORUM_SERVER_SASL_DIGEST, LOG, "QuorumLearner");

// may happen NPE at here
if (sc.hasInitialResponse()) {
responseToken = createSaslToken(new byte[0], sc, learnerLogin);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just add sc!=null is ok?

Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 nice catch, just a nitpick

@@ -134,6 +138,8 @@ public void authenticate(Socket sock, String hostName) throws IOException {

// Validate status code at the end of authentication exchange.
checkAuthStatus(sock, qpStatus);
} catch (RuntimeException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brettKK What's the point of swallowing it here?

gongleigl.gong added 2 commits March 28, 2018 19:25
@brettKK brettKK closed this Mar 28, 2018
@brettKK brettKK reopened this Mar 28, 2018
@brettKK brettKK closed this Mar 28, 2018
@brettKK brettKK reopened this Mar 28, 2018
@anmolnar
Copy link
Contributor

anmolnar commented Mar 28, 2018

@brettKK you don't need to close/reopen the pull request to trigger the build. Just amend your latest commit and do a force push.

@nkalmar
Copy link
Contributor

nkalmar commented Apr 18, 2018

+1

@anmolnar
Copy link
Contributor

@brettKK do you still work on this patch?

@lujiefsi
Copy link

Also ping @brettKK

Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think only a unit test is needed to get this patch done.

@@ -94,7 +94,10 @@ public void authenticate(Socket sock, String hostName) throws IOException {
principalConfig,
QuorumAuth.QUORUM_SERVER_PROTOCOL_NAME,
QuorumAuth.QUORUM_SERVER_SASL_DIGEST, LOG, "QuorumLearner");

if (sc == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same feedback as #495

  1. check the callers and see if it's handled properly. Likely it will be logged there as well. Verify/report.
  2. No need to say exception in an exception. The text of LOG.error line seems like it would have been a good error string for the exception itself.
  3. as previously noted, add a test.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For #1:
Follower#77,Observer#69,QuorumCnxManager#333 all have same patern:
try { //root caller } catch (IOException e) {//handler code}
#2 and #3, @brettKK .

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, it is hard for me to write a unit test for this bug, any suggestion? @brettKK @anmolnar @phunt @nkalmar @Others

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try unit test written by @brettKK ~~

brettKK and others added 25 commits June 2, 2018 07:41
del unuse

keep up with master

add NPE place

fix code

fix jenkins error

del catch

fix code

delete annotation in code

del test file

recover code

change ZOOK3007 to compare with apache master

fix format

del logger error and fix error message

fix RTE message in ReferenceCountedACLCache class

fix test

add a test , and need to do

del test file

apply anmolnar's patch
recover code

change ZOOK3007 to compare with apache master
del logger error and fix error message

fix test

apply anmolnar's patch
…ocSize()

In my latest commit regarding TxnLogToolkit there's a refactor to outsource file padding logic from FileTxnLog to a separate class:

126fb0f#diff-89717124564925d61d29dd817bcdd915L147

Unfortunately public static method setPreallocSize(int) has also been moved to the new class, but it's being actively used by hadoop-common project too:

https://github.com/apache/hadoop/blob/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/ClientBaseWithFixes.java#L384

I'd like to submit a patch to revert the deleted method which is going to call the new one, but will keep backward compatibility with Hadoop.

Author: Andor Molnar <[email protected]>

Reviewers: [email protected]

Closes #509 from anmolnar/ZOOKEEPER-3027

Change-Id: I7333b5e24c2a78d10a5c5a74c181633050bd225d

del unuse

keep up with master

fix jenkins error

del catch

fix code

recover zookeeper master same with apache:master

recover code

change ZOOK3007 to compare with apache master

fix conficit

del logger error and fix error message

fix test

apply anmolnar's patch
…ocSize()

In my latest commit regarding TxnLogToolkit there's a refactor to outsource file padding logic from FileTxnLog to a separate class:

126fb0f#diff-89717124564925d61d29dd817bcdd915L147

Unfortunately public static method setPreallocSize(int) has also been moved to the new class, but it's being actively used by hadoop-common project too:

https://github.com/apache/hadoop/blob/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/ClientBaseWithFixes.java#L384

I'd like to submit a patch to revert the deleted method which is going to call the new one, but will keep backward compatibility with Hadoop.

Author: Andor Molnar <[email protected]>

Reviewers: [email protected]

Closes #509 from anmolnar/ZOOKEEPER-3027

Change-Id: I7333b5e24c2a78d10a5c5a74c181633050bd225d

del unuse

keep up with master

fix jenkins error

del catch

fix code

recover zookeeper master same with apache:master

recover code

change ZOOK3007 to compare with apache master

fix conficit

del logger error and fix error message

fix test

apply anmolnar's patch
del unuse

keep up with master

add NPE place

fix code

fix jenkins error

del catch

fix code

delete annotation in code

del test file

recover code

change ZOOK3007 to compare with apache master

fix format

del logger error and fix error message

fix RTE message in ReferenceCountedACLCache class

fix test

add a test , and need to do

del test file

apply anmolnar's patch
# This is the 1st commit message:

fix NPE bug

# This is the commit message #2:

NPE inZOOKEEPER-3008

# This is the commit message #3:

del unuse

# This is the commit message #4:

keep up with master

# This is the commit message #5:

add NPE place

# This is the commit message #6:

fix code

# This is the commit message #7:

fix jenkins error

# This is the commit message #8:

del catch

# This is the commit message #9:

fix code

# This is the commit message #10:

delete annotation in code

# This is the commit message #11:

del test file
recover code

change ZOOK3007 to compare with apache master

fix format

del logger error and fix error message

fix RTE message in ReferenceCountedACLCache class
NPE inZOOKEEPER-3008

del unuse

keep up with master

add NPE place

fix code

fix jenkins error

del catch

fix code

delete annotation in code

del test file

merge info

recover code

change ZOOK3007 to compare with apache master

fix format

del logger error and fix error message

fix RTE message in ReferenceCountedACLCache class

NPE inZOOKEEPER-3008

del unuse

keep up with master

fix jenkins error

del catch

fix code

delete annotation in code

del test file
Copy link

@pravsingh pravsingh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comment about styling.

Do we use some sort of Checkstyle for consistent code formatting?

If not, I can create ticket and work on it.

this.learnerLogin = new Login(loginContext,
new SaslClientCallbackHandler(null, "QuorumLearner"), new ZKConfig());
this.learnerLogin = loginFactory.createLogin(loginContext,
new SaslClientCallbackHandler(null, "QuorumLearner"), new ZKConfig());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be put on above line. makes it more readable.

@anmolnar
Copy link
Contributor

anmolnar commented Aug 8, 2018

@brettKK Can we move on?
@phunt Do you approve this change?

@brettKK
Copy link
Author

brettKK commented Aug 8, 2018

@anmolnar , thanks for your attention, I will work on it this weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants