From 32eaa828b79ff010ca4a4ea1795ffa03a643c865 Mon Sep 17 00:00:00 2001 From: dmiller Date: Thu, 29 Sep 2022 22:19:28 +0000 Subject: [PATCH] Faster RPC number lookup --- nselib/rpc.lua | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/nselib/rpc.lua b/nselib/rpc.lua index 6d0595062..c3a880a1f 100644 --- a/nselib/rpc.lua +++ b/nselib/rpc.lua @@ -82,6 +82,7 @@ local nmap = require "nmap" local stdnse = require "stdnse" local string = require "string" local table = require "table" +local tableaux = require "tableaux" _ENV = stdnse.module("rpc", stdnse.seeall) -- Version 0.3 @@ -114,7 +115,7 @@ local RPC_PROTOCOLS = (nmap.registry.args and nmap.registry.args[RPC_args['rpcbi nmap.registry.args[RPC_args['rpcbind'].proto] or { "tcp", "udp" } -- used to cache the contents of the rpc datafile -local RPC_PROGRAMS +local RPC_PROGRAMS, RPC_NUMBERS -- local mutex to synchronize I/O operations on nmap.registry[host.ip]['portmapper'] local mutex = nmap.mutex("rpc") @@ -3450,13 +3451,10 @@ Util = return end end - for num, name in pairs(RPC_PROGRAMS) do - if ( prog_name == name ) then - return num - end + if not RPC_NUMBERS then + RPC_NUMBERS = tableaux.invert(RPC_PROGRAMS) end - - return + return RPC_NUMBERS[prog_name] end, --- Converts the RPC program number to its equivalent name