Set umask before calling mkstemp in unit tests. Found by coverity

This commit is contained in:
Nick Mathewson 2012-07-25 16:18:33 -04:00
parent 2259777cc8
commit f1ce15d936
2 changed files with 8 additions and 0 deletions

View File

@ -185,6 +185,7 @@ fi
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h stdarg.h inttypes.h stdint.h stddef.h poll.h unistd.h sys/epoll.h sys/time.h sys/queue.h sys/event.h sys/param.h sys/ioctl.h sys/select.h sys/devpoll.h port.h netinet/in.h netinet/in6.h sys/socket.h sys/uio.h arpa/inet.h sys/eventfd.h sys/mman.h sys/sendfile.h sys/wait.h netdb.h])
AC_CHECK_HEADERS([sys/stat.h])
AC_CHECK_HEADERS(sys/sysctl.h, [], [], [
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
@ -284,6 +285,7 @@ AC_HEADER_TIME
dnl Checks for library functions.
AC_CHECK_FUNCS([gettimeofday vasprintf fcntl clock_gettime strtok_r strsep])
AC_CHECK_FUNCS([getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice arc4random arc4random_buf issetugid geteuid getegid getprotobynumber setenv unsetenv putenv sysctl])
AC_CHECK_FUNCS([umask])
AC_CACHE_CHECK(
[for getaddrinfo],

View File

@ -58,6 +58,9 @@
#endif
#include <sys/types.h>
#ifdef _EVENT_HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifndef WIN32
#include <sys/socket.h>
@ -123,6 +126,9 @@ regress_make_tmpfile(const void *data, size_t datalen)
char tmpfilename[32];
int fd;
strcpy(tmpfilename, "/tmp/eventtmp.XXXXXX");
#ifdef _EVENT_HAVE_UMASK
umask(0077);
#endif
fd = mkstemp(tmpfilename);
if (fd == -1)
return (-1);