Nmap Development mailing list archives

Re: XML structured script output (storing results per script instance)


From: David Fifield <david () bamsoftware com>
Date: Tue, 31 Jul 2012 19:56:34 -0700

On Tue, Jul 31, 2012 at 10:14:48PM -0400, Patrick Donnelly wrote:
On Jul 31, 2012 9:08 PM, "David Fifield" <david () bamsoftware com> wrote:

Daniel's structured output branch stores the output of a script as a Lua
object in the Lua registry, in a table keyed by "NSE_SCRIPT_RESULT"] and
subkeyed by the pointer to the script instance.

Why would you store it in the lua registry?

Here's an excerpt from
ScriptResult::set_output:

  key = lua_topointer(L, pos+1);
  lua_getfield(lstate, LUA_REGISTRYINDEX, NSE_SCRIPT_RESULT); /* -3 */
  lua_pushfstring(lstate, "%p", key); /* -2 */
  lua_pushvalue(lstate, pos); /* -1 */
  lua_settable(lstate, -3); /* _R[NSE_SCRIPT_RESULT][key] = return_value
*/

Lua experts: is this the usual way to accomplish this? Is it safe to
rely on addresses in this way?

No and maybe.

So what's the recommended way to do this? Previously set_output
immediately converted a Lua string to a std::string, with no need to
hold on to a lua_State. Now set_output can receive more generally a
table, which I suggested keeping in the Lua registry rather than
converting to a C++ representation of the same table.

David Fifield
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/


Current thread: