mirror of
https://github.com/nmap/nmap.git
synced 2026-01-06 14:39:03 +00:00
use # length operator instead of string.len (canonicalize)
Used this perl command: $ # perl -pi -e 's/string\.len\((.*?)\)/#\1/g' *.nse
This commit is contained in:
@@ -366,7 +366,7 @@ function get_prefix_length( range )
|
||||
last = ipOps.ip_to_bin( last ):reverse()
|
||||
|
||||
local hostbits = 0
|
||||
for pos = 1, string.len( first ), 1 do
|
||||
for pos = 1, # first , 1 do
|
||||
|
||||
if first:sub( pos, pos ) == "0" and last:sub( pos, pos ) == "1" then
|
||||
hostbits = hostbits + 1
|
||||
@@ -376,7 +376,7 @@ function get_prefix_length( range )
|
||||
|
||||
end
|
||||
|
||||
return ( string.len( first ) - hostbits )
|
||||
return ( # first - hostbits )
|
||||
|
||||
end
|
||||
|
||||
@@ -394,7 +394,7 @@ function get_assignment( ip, prefix )
|
||||
if err then return nil, err end
|
||||
|
||||
prefix = tonumber( prefix )
|
||||
if not prefix or ( prefix < 0 ) or ( prefix > string.len( some_ip ) ) then
|
||||
if not prefix or ( prefix < 0 ) or ( prefix > # some_ip ) then
|
||||
return nil, "Error in get_assignment: Invalid prefix length."
|
||||
end
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ action = function(host, port)
|
||||
-- Now we need to "parse" the results to check to see if they are good
|
||||
|
||||
-- We need a minimum of 5 bytes...
|
||||
if (string.len(result) < 5) then
|
||||
if (#result < 5) then
|
||||
if (nmap.verbosity() >= 2 or nmap.debugging() >= 1) then
|
||||
return "ERROR: Malformed response"
|
||||
else
|
||||
@@ -133,7 +133,7 @@ action = function(host, port)
|
||||
end
|
||||
|
||||
-- We need a minimum of 128 bytes...
|
||||
if (string.len(result) < 128) then
|
||||
if (#result < 128) then
|
||||
if (nmap.verbosity() >= 2 or nmap.debugging() >= 1) then
|
||||
return "ERROR: Truncated response"
|
||||
else
|
||||
@@ -171,7 +171,7 @@ action = function(host, port)
|
||||
local txtlen = string.byte(result, 128)
|
||||
|
||||
-- We now need a minimum of 128 + txtlen bytes + 1...
|
||||
if (string.len(result) < 128 + txtlen) then
|
||||
if (#result < 128 + txtlen) then
|
||||
if (nmap.verbosity() >= 2 or nmap.debugging() >= 1) then
|
||||
return "ERROR: Truncated response"
|
||||
else
|
||||
|
||||
@@ -83,7 +83,7 @@ action = function(host, port)
|
||||
-- Now we need to "parse" the results to check to see if they are good
|
||||
|
||||
-- We need a minimum of 5 bytes...
|
||||
if (string.len(result) < 5) then
|
||||
if (#result < 5) then
|
||||
if (nmap.verbosity() >= 2 or nmap.debugging() >= 1) then
|
||||
return "ERROR: Malformed response"
|
||||
else
|
||||
@@ -133,7 +133,7 @@ action = function(host, port)
|
||||
end
|
||||
|
||||
-- We need a minimum of 128 bytes...
|
||||
if (string.len(result) < 128) then
|
||||
if (#result < 128) then
|
||||
if (nmap.verbosity() >= 2 or nmap.debugging() >= 1) then
|
||||
return "ERROR: Truncated response"
|
||||
else
|
||||
@@ -171,7 +171,7 @@ action = function(host, port)
|
||||
local txtlen = string.byte(result, 128)
|
||||
|
||||
-- We now need a minimum of 128 + txtlen bytes + 1...
|
||||
if (string.len(result) < 128 + txtlen) then
|
||||
if (#result < 128 + txtlen) then
|
||||
if (nmap.verbosity() >= 2 or nmap.debugging() >= 1) then
|
||||
return "ERROR: Truncated response"
|
||||
else
|
||||
|
||||
@@ -228,7 +228,7 @@ function build_domain(host)
|
||||
|
||||
-- prepend each element with its length
|
||||
while i <= #abs_name do
|
||||
buf = buf .. string.char(string.len(abs_name[i])) .. abs_name[i]
|
||||
buf = buf .. string.char(#abs_name[i]) .. abs_name[i]
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
@@ -373,7 +373,7 @@ function responses_iter(data)
|
||||
return function()
|
||||
local length, remaining, response
|
||||
|
||||
remaining = string.len(data) - offset + 1
|
||||
remaining = #data - offset + 1
|
||||
if remaining == 0 then
|
||||
return nil
|
||||
end
|
||||
@@ -551,7 +551,7 @@ action = function(host, port)
|
||||
local req_id = '\222\173'
|
||||
local offset = 1
|
||||
local name = build_domain(string.lower(dns_opts.domain))
|
||||
local pkt_len = string.len(name) + 16
|
||||
local pkt_len = #name + 16
|
||||
|
||||
-- build axfr request
|
||||
local buf = strbuf.new()
|
||||
@@ -571,7 +571,7 @@ action = function(host, port)
|
||||
soc:close()
|
||||
|
||||
local response_str = strbuf.dump(response)
|
||||
local length = string.len(response_str)
|
||||
local length = #response_str
|
||||
|
||||
-- check server response code
|
||||
if length < 6 or
|
||||
|
||||
@@ -75,7 +75,7 @@ action = function(host, port)
|
||||
|
||||
if title and title ~= "" then
|
||||
result = string.gsub(title , "[\n\r\t]", "")
|
||||
if string.len(title) > 65 then
|
||||
if #title > 65 then
|
||||
stdnse.print_debug("http-title.nse: (%s) Title got truncated!", host.targetname or host.ip );
|
||||
result = string.sub(result, 1, 62) .. "..."
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ action = function(host, port)
|
||||
return
|
||||
end
|
||||
|
||||
if (string.len(recv)) == 12 then
|
||||
if (#recv) == 12 then
|
||||
local byte11 = string.format("%02X", string.byte(recv, 11))
|
||||
local byte12 = string.format("%02X", string.byte(recv, 12))
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ action = function(host)
|
||||
local names_output = {}
|
||||
names_output['name'] = "Names"
|
||||
for i = 1, #names, 1 do
|
||||
local padding = string.rep(" ", 17 - string.len(names[i]['name']))
|
||||
local padding = string.rep(" ", 17 - #names[i]['name'])
|
||||
local flags_str = netbios.flags_to_string(names[i]['flags'])
|
||||
table.insert(names_output, string.format("%s<%02x>%sFlags: %s", names[i]['name'], names[i]['suffix'], padding, flags_str))
|
||||
end
|
||||
|
||||
@@ -243,9 +243,9 @@ end
|
||||
--@return An integer representing the checksum.
|
||||
local function p2p_checksum(data)
|
||||
local pos, i
|
||||
local hash = string.len(data)
|
||||
local hash = #data
|
||||
|
||||
stdnse.print_debug(2, "Conficker: Calculating checksum for %d-byte buffer", string.len(data))
|
||||
stdnse.print_debug(2, "Conficker: Calculating checksum for %d-byte buffer", #data)
|
||||
|
||||
-- Get the first character
|
||||
pos, i = bin.unpack("<C", data)
|
||||
@@ -274,7 +274,7 @@ local function p2p_cipher(packet, key1, key2)
|
||||
local i
|
||||
local buf = ""
|
||||
|
||||
for i = 1, string.len(packet), 1 do
|
||||
for i = 1, #packet, 1 do
|
||||
-- Do a 64-bit rotate on key1:key2
|
||||
key2, key1 = rot64(key2, key1)
|
||||
|
||||
@@ -441,7 +441,7 @@ local function p2p_create_packet(protocol, do_encryption)
|
||||
|
||||
-- Add the length in front if it's TCP
|
||||
if(protocol == "tcp") then
|
||||
packet = bin.pack("<SA", string.len(packet), packet)
|
||||
packet = bin.pack("<SA", #packet, packet)
|
||||
end
|
||||
|
||||
return true, packet
|
||||
@@ -493,7 +493,7 @@ local function conficker_check(ip, port, protocol)
|
||||
local length
|
||||
_, length = bin.unpack("<S", response, 1)
|
||||
|
||||
while length > (string.len(response) - 2) do
|
||||
while length > (#response - 2) do
|
||||
local response2
|
||||
|
||||
status, response2 = socket:receive_bytes(2)
|
||||
|
||||
@@ -71,7 +71,7 @@ action = function(host, port)
|
||||
|
||||
-- get the vendor (should be 64 octets, but capture to end of the string to be safe)
|
||||
local s4, length
|
||||
length = string.len(result)
|
||||
length = #result
|
||||
s4 = string.sub(result, 88, length)
|
||||
vendor = string.match(s4, "(.-)%z")
|
||||
|
||||
|
||||
@@ -921,7 +921,7 @@ local function cipher(str, config)
|
||||
c = string.char(bit.bxor(c, string.byte(config.key, config.key_index + 1)))
|
||||
|
||||
config.key_index = config.key_index + 1
|
||||
config.key_index = config.key_index % string.len(config.key)
|
||||
config.key_index = config.key_index % #config.key
|
||||
|
||||
result = result .. c
|
||||
end
|
||||
|
||||
@@ -177,7 +177,7 @@ local function find_links(list, base_path, page, host)
|
||||
|
||||
for w in string.gmatch(page, 'href%s*=%s*"%s*[^"]+%s*"') do
|
||||
s, e = string.find(w, '"')
|
||||
httpurl = string.sub(w, s+1, string.len(w)-1)
|
||||
httpurl = string.sub(w, s+1, #w-1)
|
||||
i = 1
|
||||
|
||||
-- parse out duplicates, otherwise we'll be here all day
|
||||
|
||||
@@ -61,7 +61,7 @@ cyphers = function(cypher_list, len)
|
||||
|
||||
if (len == 0) then return "none"; end
|
||||
-- something's got broken along the way if these aren't equal
|
||||
if (len ~= string.len(cypher_list)) then
|
||||
if (len ~= #cypher_list) then
|
||||
return "";
|
||||
end
|
||||
|
||||
@@ -94,7 +94,7 @@ give_n_bytes = function(idx, n, str)
|
||||
|
||||
-- returns the next n bytes of a string
|
||||
|
||||
if (idx + (n - 1) > string.len(str)) then
|
||||
if (idx + (n - 1) > #str) then
|
||||
return (idx + n), string.rep(string.char(0x00), n);
|
||||
end
|
||||
|
||||
@@ -173,8 +173,8 @@ action = function(host, port)
|
||||
return;
|
||||
end
|
||||
--try to get entire hello, if we don't already
|
||||
if (string.len(server_hello) < server_hello_len) then
|
||||
status, tmp = socket:receive_bytes(server_hello_len - string.len(server_hello));
|
||||
if (#server_hello < server_hello_len) then
|
||||
status, tmp = socket:receive_bytes(server_hello_len - #server_hello);
|
||||
|
||||
if (not status) then
|
||||
socket:close();
|
||||
|
||||
@@ -427,7 +427,7 @@ function get_prefix_length( range )
|
||||
last = ipOps.ip_to_bin( last ):reverse()
|
||||
|
||||
local hostbits = 0
|
||||
for pos = 1, string.len( first ), 1 do
|
||||
for pos = 1, # first , 1 do
|
||||
|
||||
if first:sub( pos, pos ) == "0" and last:sub( pos, pos ) == "1" then
|
||||
hostbits = hostbits + 1
|
||||
@@ -437,7 +437,7 @@ function get_prefix_length( range )
|
||||
|
||||
end
|
||||
|
||||
return ( string.len( first ) - hostbits )
|
||||
return ( # first - hostbits )
|
||||
|
||||
end
|
||||
|
||||
@@ -1159,7 +1159,7 @@ function get_assignment( ip, prefix )
|
||||
if err then return nil, err end
|
||||
|
||||
prefix = tonumber( prefix )
|
||||
if not prefix or ( prefix < 0 ) or ( prefix > string.len( some_ip ) ) then
|
||||
if not prefix or ( prefix < 0 ) or ( prefix > # some_ip ) then
|
||||
return nil, "Error in get_assignment: Invalid prefix length."
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user