1
0
mirror of https://github.com/nmap/nmap.git synced 2026-02-03 20:16:33 +00:00

Use mkstemp instead of tempnam.

See http://seclists.org/nmap-dev/2012/q4/334 for why this wasn't really
a big problem. This solution is essentially how netcat-openbsd does it:
mkstemp creates the file and opens it, but then we just unlink it and
only use the returned name. Functionality is pretty much the same as the
tempnam version.
This commit is contained in:
dmiller
2015-11-20 16:17:26 +00:00
parent 32b28a8726
commit 72a8cc3b26
4 changed files with 16 additions and 2 deletions

View File

@@ -43,6 +43,9 @@
/* Define to 1 if you have the `memset' function. */
#undef HAVE_MEMSET
/* Define to 1 if you have the `mkstemp' function. */
#undef HAVE_MKSTEMP
/* Define to 1 if you have the <netdb.h> header file. */
#undef HAVE_NETDB_H

2
ncat/configure vendored
View File

@@ -4401,7 +4401,7 @@ fi
done
for ac_func in dup2 gettimeofday inet_ntoa memset select socket strcasecmp strchr strdup strerror strncasecmp strtol
for ac_func in dup2 gettimeofday inet_ntoa memset mkstemp select socket strcasecmp strchr strdup strerror strncasecmp strtol
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

View File

@@ -51,7 +51,7 @@ AC_FUNC_FORK
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([dup2 gettimeofday inet_ntoa memset select socket strcasecmp strchr strdup strerror strncasecmp strtol])
AC_CHECK_FUNCS([dup2 gettimeofday inet_ntoa memset mkstemp select socket strcasecmp strchr strdup strerror strncasecmp strtol])
AC_SEARCH_LIBS(setsockopt, socket)
# Ncat does not call gethostbyname directly, but some of the libraries
# it links to (such as libpcap) do. Instead it calls getaddrinfo. At

View File

@@ -909,9 +909,20 @@ int ncat_connect(void)
{
if (srcaddr.storage.ss_family != AF_UNIX) {
char *tmp_name = NULL;
#if HAVE_MKSTEMP
char *tmpdir = getenv("TMPDIR");
size_t size=0, offset=0;
strbuf_sprintf(&tmp_name, &size, &offset, "%s/ncat.XXXXXX",
tmpdir ? tmpdir : "/tmp");
if (mkstemp(tmp_name) == -1) {
bye("Failed to create name for temporary DGRAM source Unix domain socket (mkstemp).");
}
unlink(tmp_name);
#else
/* If no source socket was specified, we have to create temporary one. */
if ((tmp_name = tempnam(NULL, "ncat.")) == NULL)
bye("Failed to create name for temporary DGRAM source Unix domain socket (tempnam).");
#endif
srcaddr.un.sun_family = AF_UNIX;
strncpy(srcaddr.un.sun_path, tmp_name, sizeof(srcaddr.un.sun_path));