Nmap Development mailing list archives

[PATCH] close() stdout/stderr before dup2() in interactive mode


From: Kris Katterjohn <kjak () ispwest com>
Date: Tue, 05 Sep 2006 11:48:02 -0500

The attached patch closes stdout and stderr before the
conditionally-called dup2()s when using the 'f' command in interactive
mode. Not only because dup2() calls close() and any errors that would be
reported would be lost, but mainly because if DEVNULL fails to open,
everything is still printed to stdout and stderr if they aren't closed.

I usually just close stdout and stderr in my things, but if redirecting
to /dev/null is better, at least they'll be closed if open() fails.

It's a diff against 4.20ALPHA6.

Thanks,
Kris Katterjohn
--- x/main.cc   2006-08-31 00:29:11.000000000 -0500
+++ y/main.cc   2006-09-05 11:38:30.000000000 -0500
@@ -377,6 +377,8 @@ int main(int argc, char *argv[]) {
        if (o.debugging) error("About to exec %s", nmappath);
        /* Kill stdout & stderr */
        if (!o.debugging) {
+         close(STDOUT_FILENO);
+         close(STDERR_FILENO);
          fd = open(DEVNULL, O_WRONLY);
          if (fd != -1) {
            dup2(fd, STDOUT_FILENO);

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

Current thread: