diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index f7de942c6db..882ab5ea7bc 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -269,6 +269,9 @@ Trunk (Unreleased) HADOOP-9433 TestLocalFileSystem#testHasFileDescriptor leaks file handle (Chris Nauroth via sanjay) + HADOOP-9806 PortmapInterface should check if the procedure is out-of-range + (brandonli) + OPTIMIZATIONS HADOOP-7761. Improve the performance of raw comparisons. (todd) diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/PortmapInterface.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/PortmapInterface.java index 26d3d774647..ae968cb046d 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/PortmapInterface.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/PortmapInterface.java @@ -45,6 +45,9 @@ public interface PortmapInterface { } public static Procedure fromValue(int value) { + if (value < 0 || value >= values().length) { + return null; + } return values()[value]; } } diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/RpcProgramPortmap.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/RpcProgramPortmap.java index cbf381296a7..c715d33e3cb 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/RpcProgramPortmap.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/RpcProgramPortmap.java @@ -131,29 +131,22 @@ public class RpcProgramPortmap extends RpcProgram implements PortmapInterface { @Override public XDR handleInternal(RpcCall rpcCall, XDR in, XDR out, InetAddress client, Channel channel) { - Procedure procedure = Procedure.fromValue(rpcCall.getProcedure()); + final Procedure portmapProc = Procedure.fromValue(rpcCall.getProcedure()); int xid = rpcCall.getXid(); - switch (procedure) { - case PMAPPROC_NULL: + if (portmapProc == Procedure.PMAPPROC_NULL) { out = nullOp(xid, in, out); - break; - case PMAPPROC_SET: + } else if (portmapProc == Procedure.PMAPPROC_SET) { out = set(xid, in, out); - break; - case PMAPPROC_UNSET: + } else if (portmapProc == Procedure.PMAPPROC_UNSET) { out = unset(xid, in, out); - break; - case PMAPPROC_DUMP: + } else if (portmapProc == Procedure.PMAPPROC_DUMP) { out = dump(xid, in, out); - break; - case PMAPPROC_GETPORT: + } else if (portmapProc == Procedure.PMAPPROC_GETPORT) { out = getport(xid, in, out); - break; - case PMAPPROC_GETVERSADDR: + } else if (portmapProc == Procedure.PMAPPROC_GETVERSADDR) { out = getport(xid, in, out); - break; - default: - LOG.info("PortmapHandler unknown rpc procedure=" + procedure); + } else { + LOG.info("PortmapHandler unknown rpc procedure=" + portmapProc); RpcAcceptedReply.voidReply(out, xid, RpcAcceptedReply.AcceptState.PROC_UNAVAIL); }