mirror of
https://github.com/nmap/nmap.git
synced 2026-10-20 19:01:56 +00:00
Let charset arg to stdnse.generate_random_string be a string
The charset argument was intended to be a table, since Lua doesn't allow indexing strings with []. Unfortunately, irc-brute and tftp-enum passed a string instead, which meant that the output was always the empty string. This change allows both formats, and fixes those scripts. irc-brute and tftp-enum had been broken since r33632 (no released version of Nmap)
This commit is contained in:
parent
3ee9fee2e2
commit
8f939279ca
1 changed files with 10 additions and 3 deletions
|
|
@ -252,7 +252,7 @@ end
|
|||
-- You can either provide your own charset or the function will use
|
||||
-- a default one which is [A-Z].
|
||||
-- @param len Length of the string we want to generate.
|
||||
-- @param charset Charset that will be used to generate the string.
|
||||
-- @param charset Charset that will be used to generate the string. String or table
|
||||
-- @return A random string of length <code>len</code> consisting of
|
||||
-- characters from <code>charset</code> if one was provided, otherwise
|
||||
-- <code>charset</code> defaults to [A-Z] letters.
|
||||
|
|
@ -261,8 +261,15 @@ function generate_random_string(len, charset)
|
|||
local ascii_A = 65
|
||||
local ascii_Z = 90
|
||||
if charset then
|
||||
for i=1,len do
|
||||
t[i]=charset[random(#charset)]
|
||||
if type(charset) == "string" then
|
||||
for i=1,len do
|
||||
local r = random(#charset)
|
||||
t[i] = sub(charset, r, r)
|
||||
end
|
||||
else
|
||||
for i=1,len do
|
||||
t[i]=charset[random(#charset)]
|
||||
end
|
||||
end
|
||||
else
|
||||
for i=1,len do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue