diff --git a/nselib/proxy.lua b/nselib/proxy.lua index a773b0f8a..73c37bfbc 100644 --- a/nselib/proxy.lua +++ b/nselib/proxy.lua @@ -22,8 +22,8 @@ local function check_code(result) if result:match( "\r?\n\r?\n" ) then result = result:match( "^(.-)\r?\n\r?\n(.*)$" ) end - if string.match(result:lower(),"^http/%d\.%d%s*200") then return true end - if string.match(result:lower(),"^http/%d\.%d%s*30[12]") then return true end + if result:lower():match("^http/%d\.%d%s*200") then return true end + if result:lower():match("^http/%d\.%d%s*30[12]") then return true end end return false end @@ -34,13 +34,10 @@ end --@return true if pattern is found, otherwise false local function check_pattern(result, pattern) local lines = stdnse.strsplit("\n", result) - local i = 1 - local n = table.getn(lines) - while true do - if i > n then return false end - if string.match(lines[i]:lower(),pattern:lower()) then return true end - i = i + 1 + for i, line in ipairs(lines) do + if line:lower():match(pattern:lower()) then return true end end + return false end --- check, decides what kind of check should be done on the response, diff --git a/nselib/tftp.lua b/nselib/tftp.lua index 42a75fecc..17bc9410e 100644 --- a/nselib/tftp.lua +++ b/nselib/tftp.lua @@ -133,10 +133,9 @@ local function dispatcher() s_condvar "broadcast" end - local n = table.getn(threads) - if ( n == 0 ) then break end - for i=1,n do - local status, res = coroutine.resume(threads[i]) + if #threads == 0 then break end + for i, thread in ipairs(threads) do + local status, res = coroutine.resume(thread) if ( not(res) ) then -- thread finished its task? table.remove(threads, i) break @@ -336,4 +335,4 @@ function waitFile( filename, timeout ) waitLast() return false -end \ No newline at end of file +end diff --git a/nselib/url.lua b/nselib/url.lua index 29da0c372..1c3dfa025 100644 --- a/nselib/url.lua +++ b/nselib/url.lua @@ -257,8 +257,8 @@ function parse_path(path) path = path or "" --path = string.gsub(path, "%s", "") string.gsub(path, "([^/]+)", function (s) table.insert(parsed, s) end) - for i = 1, table.getn(parsed) do - parsed[i] = unescape(parsed[i]) + for i, v in ipairs(parsed) do + parsed[i] = unescape(v) end if string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 end if string.sub(path, -1, -1) == "/" then parsed.is_directory = 1 end @@ -273,7 +273,7 @@ end ----------------------------------------------------------------------------- function build_path(parsed, unsafe) local path = "" - local n = table.getn(parsed) + local n = #parsed if unsafe then for i = 1, n-1 do path = path .. parsed[i]