Set umask before mkstemp() for some versions of glibc

This commit is contained in:
Mukund Sivaraman 2008-08-24 12:02:54 +05:30
parent ee70057f76
commit b6bd791e24
4 changed files with 16 additions and 1 deletions

View File

@ -73,6 +73,11 @@ _child_lock_init(void)
{ {
char lock_file[] = "/tmp/tinyproxy.servers.lock.XXXXXX"; char lock_file[] = "/tmp/tinyproxy.servers.lock.XXXXXX";
/* Only allow u+rw bits. This may be required for some versions
* of glibc so that mkstemp() doesn't make us vulnerable.
*/
umask(0177);
lock_fd = mkstemp(lock_file); lock_fd = mkstemp(lock_file);
unlink(lock_file); unlink(lock_file);

View File

@ -38,7 +38,7 @@ makedaemon(void)
exit(0); exit(0);
chdir("/"); chdir("/");
umask(077); umask(0177);
#if NDEBUG #if NDEBUG
/* /*

View File

@ -114,6 +114,11 @@ malloc_shared_memory(size_t size)
strlcpy(buffer, shared_file, sizeof(buffer)); strlcpy(buffer, shared_file, sizeof(buffer));
/* Only allow u+rw bits. This may be required for some versions
* of glibc so that mkstemp() doesn't make us vulnerable.
*/
umask(0177);
if ((fd = mkstemp(buffer)) == -1) if ((fd = mkstemp(buffer)) == -1)
return (void *)MAP_FAILED; return (void *)MAP_FAILED;
unlink(buffer); unlink(buffer);

View File

@ -165,6 +165,11 @@ main(int argc, char **argv)
} }
#endif /* HAVE_SETRLIMIT */ #endif /* HAVE_SETRLIMIT */
/* Only allow u+rw bits. This may be required for some versions
* of glibc so that mkstemp() doesn't make us vulnerable.
*/
umask(0177);
/* Default configuration file location */ /* Default configuration file location */
config.config_file = DEFAULT_CONF_FILE; config.config_file = DEFAULT_CONF_FILE;