mirror of
https://github.com/nmap/nmap.git
synced 2025-12-16 12:49:02 +00:00
Use tempfile in place of tempnam.
To avoid new GCC warnings about tempnam: ncat_connect.c:789: warning: the use of `tempnam' is dangerous, better use `mkstemp' Doing things this way has the same race condition as tempnam did, because we are unlinking the file before binding it. (The race window is smaller now.) The file must not exist before binding the Unix socket, or else you get an "address already in use" error. Unlinking before binding is the same thing that netcat-openbsd does. See this earlier thread: http://seclists.org/nmap-dev/2012/q4/336.
This commit is contained in:
@@ -560,7 +560,7 @@ int ncat_connect(void)
|
||||
if (srcaddr.storage.ss_family != AF_UNIX) {
|
||||
char *tmp_name = NULL;
|
||||
/* If no source socket was specified, we have to create temporary one. */
|
||||
if ((tmp_name = tempnam(NULL, "ncat.")) == NULL)
|
||||
if ((tmp_name = tempfile(NULL, "ncat.")) == NULL)
|
||||
bye("Failed to create name for temporary DGRAM source Unix domain socket (tempnam).");
|
||||
|
||||
srcaddr.un.sun_family = AF_UNIX;
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
|
||||
|
||||
static int mksock_bind_addr(mspool *ms, msiod *iod) {
|
||||
const char *path;
|
||||
int rc;
|
||||
int one = 1;
|
||||
|
||||
@@ -78,13 +79,15 @@ static int mksock_bind_addr(mspool *ms, msiod *iod) {
|
||||
socket_strerror(err), err);
|
||||
}
|
||||
|
||||
nsock_log_info(ms, "Binding to %s (IOD #%li)", get_localaddr_string(iod), iod->id);
|
||||
path = get_localaddr_string(iod);
|
||||
unlink(path);
|
||||
nsock_log_info(ms, "Binding to %s (IOD #%li)", path, iod->id);
|
||||
rc = bind(iod->sd, (struct sockaddr *)&iod->local, (int) iod->locallen);
|
||||
if (rc == -1) {
|
||||
int err = socket_errno();
|
||||
|
||||
nsock_log_error(ms, "Bind to %s failed (IOD #%li): %s (%d)",
|
||||
get_localaddr_string(iod), iod->id,
|
||||
path, iod->id,
|
||||
socket_strerror(err), err);
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user