From 60be5fb9ed0f9f9e3c61f831a923f44bdb2c77b2 Mon Sep 17 00:00:00 2001 From: Brandon Li Date: Thu, 1 Aug 2013 17:48:01 +0000 Subject: [PATCH] HADOOP-9806 PortmapInterface should check if the procedure is out-of-range. Contributed by Brandon Li git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1509347 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 +++ .../hadoop/portmap/PortmapInterface.java | 3 +++ .../hadoop/portmap/RpcProgramPortmap.java | 25 +++++++------------ 3 files changed, 15 insertions(+), 16 deletions(-) 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); }