diff --git a/nse_nmaplib.cc b/nse_nmaplib.cc index 797284d6e..1ffd44065 100644 --- a/nse_nmaplib.cc +++ b/nse_nmaplib.cc @@ -402,13 +402,14 @@ static int l_print_debug_unformatted(lua_State *l) { int verbosity=1, stack_counter(1); const char *out; - if (lua_isnumber (l, 1) && (lua_gettop(l) > 1)) { - verbosity = lua_tointeger(l, 1); - if (verbosity > o.verbose) return 0; - stack_counter++; - } - out = luaL_checkstring(l, stack_counter); - log_write(LOG_STDOUT, "%s NSE DEBUG: %s\n", SCRIPT_ENGINE, out); + if (lua_gettop(l) != 2) return luaL_error(l, "Incorrect number of arguments\n"); + + verbosity = luaL_checkinteger(l, 1); + if (verbosity > o.verbose) return 0; + out = luaL_checkstring(l, 2); + + log_write(LOG_STDOUT, "%s DEBUG: %s\n", SCRIPT_ENGINE, out); + return 0; } diff --git a/nselib/stdnse.lua b/nselib/stdnse.lua new file mode 100644 index 000000000..b11fc2224 --- /dev/null +++ b/nselib/stdnse.lua @@ -0,0 +1,9 @@ +print_debug = function(...) + local verbosity = 1; + if ((#arg > 1) and (tonumber(arg[1]))) then + verbosity = table.remove(arg, 1); + end + + nmap.print_debug_unformatted(verbosity, string.format(unpack(arg, start))); +end + diff --git a/scripts/showHTMLTitle.nse b/scripts/showHTMLTitle.nse index 149d179bf..e63cf8538 100644 --- a/scripts/showHTMLTitle.nse +++ b/scripts/showHTMLTitle.nse @@ -50,7 +50,7 @@ action = function(host, port) if title ~= nil then result = string.gsub(title , "[\n\r\t]", "") if string.len(title) > 50 then - nmap.print_debug_unformatted("showHTMLTitle.nse: Title got truncated!"); + nmap.print_debug("showHTMLTitle.nse: Title got truncated!"); result = string.sub(result, 1, 62) .. "..." end else