HDFS-13485. DataNode WebHDFS endpoint throws NPE. Contributed by Siyao Meng.

This commit is contained in:
Wei-Chiu Chuang 2018-07-16 15:45:55 -07:00
parent 121865c3f9
commit d215357718
2 changed files with 23 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import com.google.protobuf.ByteString;
import com.google.common.primitives.Bytes;
import org.apache.commons.codec.binary.Base64;
import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.conf.Configuration;
@ -358,6 +359,10 @@ public class Token<T extends TokenIdentifier> implements Writable {
*/
private static void decodeWritable(Writable obj,
String newValue) throws IOException {
if (newValue == null) {
throw new HadoopIllegalArgumentException(
"Invalid argument, newValue is null");
}
Base64 decoder = new Base64(0, null, true);
DataInputBuffer buf = new DataInputBuffer();
byte[] decoded = decoder.decode(newValue);

View File

@ -21,6 +21,7 @@ package org.apache.hadoop.security.token;
import java.io.*;
import java.util.Arrays;
import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.io.*;
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier;
import org.apache.hadoop.security.token.delegation.TestDelegationToken.TestDelegationTokenIdentifier;
@ -100,6 +101,23 @@ public class TestToken {
}
}
/*
* Test decodeWritable() with null newValue string argument,
* should throw HadoopIllegalArgumentException.
*/
@Test
public void testDecodeWritableArgSanityCheck() throws Exception {
Token<AbstractDelegationTokenIdentifier> token =
new Token<AbstractDelegationTokenIdentifier>();
try {
token.decodeFromUrlString(null);
fail("Should have thrown HadoopIllegalArgumentException");
}
catch (HadoopIllegalArgumentException e) {
Token.LOG.info("Test decodeWritable() sanity check success.");
}
}
@Test
public void testDecodeIdentifier() throws IOException {
TestDelegationTokenSecretManager secretManager =