Nmap Development mailing list archives

[NSE] [PATCH] Fix for stdnse.format_output()


From: Ron <ron () skullsecurity net>
Date: Tue, 9 Nov 2010 20:30:17 -0600

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This is a pretty small change, but stdnse.format_output() is pretty important so I don't want to risk completely 
breaking it. 

Basically, this fixes a bug where the 'name' or 'warning' fields wouldn't be displayed for top-level data. It moves the 
'name'/'warning' checks to the top of the function, before the tables start being processed. I believe it works, but 
I'd like to get a second opinion:

Index: nselib/stdnse.lua
===================================================================
- --- nselib/stdnse.lua   (revision 20986)
+++ nselib/stdnse.lua   (working copy)
@@ -460,18 +460,18 @@
   -- Make sure we have an indent value
   indent = indent or {}
 
+  if(data['name']) then
+    if(data['warning'] and nmap.debugging() > 0) then
+      output = output .. format("%s%s%s (WARNING: %s)\n", format_get_indent(indent), prefix, data['name'], 
data['warning'])
+    else
+      output = output .. format("%s%s%s\n", format_get_indent(indent), prefix, data['name'])
+    end
+  elseif(data['warning'] and nmap.debugging() > 0) then
+      output = output .. format("%s%s(WARNING: %s)\n", format_get_indent(indent), prefix, data['warning'])
+  end
+
   for i, value in ipairs(data) do
     if(type(value) == 'table') then
- -      if(value['name']) then
- -        if(value['warning'] and nmap.debugging() > 0) then
- -          output = output .. format("%s  %s%s (WARNING: %s)\n", format_get_indent(indent), prefix, value['name'], 
value['warning'])
- -        else
- -          output = output .. format("%s  %s%s\n", format_get_indent(indent), prefix, value['name'])
- -        end
- -      elseif(value['warning'] and nmap.debugging() > 0) then
- -          output = output .. format("%s  %s(WARNING: %s)\n", format_get_indent(indent), prefix, value['warning'])
- -      end
- -
       -- Do a shallow copy of indent
       local new_indent = {}
       for _, v in ipairs(indent) do
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkzaA7kACgkQ2t2zxlt4g/R4iwCgmSELguVUOCLmQ3DDJZS6bGxH
zNkAn0EypTraT01bCrTUAdE5h8D3yxXb
=FJh4
-----END PGP SIGNATURE-----
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/


Current thread: