Nmap Development mailing list archives

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


From: Patrick Donnelly <batrick () batbytes com>
Date: Fri, 3 Aug 2012 17:51:50 -0400

On Thu, Aug 2, 2012 at 11:05 PM, Daniel Miller <bonsaiviking () gmail com> wrote:
I think I get it. I've attached a couple patches; does the 0030 patch
handle this correctly now? Also, I think I did the right thing in the
0031 patch in order to wrap the call in lua_pcall. Am I missing
anything there that you can see? Thanks so much for your help with
this.

For 0030:

+  if (key != LUA_NOREF) {
+    lua_getfield(L_NSE, LUA_REGISTRYINDEX, NSE_SCRIPT_RESULT); /* -2 */
+    luaL_unref(L_NSE, -1, key); /* _R[NSE_SCRIPT_RESULT][key] = nil */
+    lua_pop(L_NSE, 1);
+  }

set key to LUA_NOREF.

For 0031:

script_output_xml should get the key from NSE_SCRIPT_RESULT itself
since lua_getfield can throw an error (something we're trying to avoid
using pcall). It should look like:

+    lua_pushcfunction(L_NSE, nseU_traceback); /* top+2 (msgh handler) */
+    lua_pushcfunction(L_NSE, script_output_xml); /* top+3 (output function) */
+    lua_pushinteger(L_NSE, key);
+    if (lua_pcall(L_NSE, 1, 0, 1)) /* -2 + 1 */

Because the call to ScriptResult::write_xml() comes from output.cc, I
really don't see how to make this an entirely-Lua problem. I would
like to, since the recursive traversal would be cleaner in Lua than in
C, but I've already got the necessary functions written, and I think
to call back to Lua from C would require stashing a Lua function
somewhere in the registry, which seems more messy than it is worth.
Thoughts?

It's fine. I'm mostly concerned about leaking memory due to the design.

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


Current thread: