Nmap Development mailing list archives

"\r\r" in script output


From: David Fifield <david () bamsoftware com>
Date: Mon, 8 Sep 2008 13:35:47 -0600

On Sun, Sep 07, 2008 at 02:18:33AM -0600, David Fifield wrote:
On Sat, Sep 06, 2008 at 01:30:19PM -0700, Fyodor wrote:
I'm happy to report that David's setup.py fix allowed me to create a
working Nmap Windows installer.  I tested Zenmap, and it worked
against scanme.nmap.org.  But then I tried against a machine on my
locan network and it crashed :(.  Here is the command:

nmap -T Aggressive -A flog.yuma.net

Zenmap reported:

--
"Gtk-ERROR **: Char offset 64 is off the end of the line
aborting...
[OK]
--

We figured this bug out eventually. It had to do with Zenmap breaking
lines differently than PyGTK was in the syntax highlighting module.

The bug was uncovered because some script output has \r\r sequences in
it. (PyGTK was breaking lines between each \r, and Zenmap wasn't.) We
fixed the bug but the question arises: Where are the \r\r sequences
coming from?

It might be in this code in formatScriptOutput in output.cc:

#ifdef WIN32
        const char* sep = "\r\n";
#else
        const char* sep = "\n";
#endif
        std::string line_prfx = "|  ";

        char* token = strtok(c_output, sep);

        result += line_prfx + sr.get_id() + ": ";

        while(token != NULL) {
                if(line > 0)
                        result += line_prfx;
                result += std::string(token) + sep;
                token = strtok(NULL, sep);
                line++;
        }

On Windows that's appending "\r\n" to the end of every line of script
output. But I think Windows automatically converts "\n" to "\r\n" for
text streams (such as stdout), so perhaps it's becoming "\r\r\n".
Indeed, in the debugging output Fyodor made for me there are lines like

Starting Nmap 4.69BETA1 ( http://nmap.org ) at 2008-09-07 00:46 Pacific Daylight Time\r\n

which in the source are ended with a plain "\n". So the "\r" should not
be necessary. I have attached a patch that ends the lines with plain
"\n".

But is it even necessary to look for "\r" in the calls to strtok? The
output of NSE scripts should be delimited with plain "\n". It should
only get changed to "\r\n" (by the WIndows C library) when it's written
to the screen or a file.

David Fifield

Attachment: nse-output-lineend.diff
Description:


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

Current thread: