If available, use O_TMPFILE, fix insecure tempfile found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
3cff584621
commit
ec06b220e4
@ -2249,8 +2249,20 @@ static int cffwd(void)
|
|||||||
static FILE *cftemp(void)
|
static FILE *cftemp(void)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
#ifdef O_TMPFILE
|
||||||
|
mode_t oldmask;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
oldmask = umask(0077);
|
||||||
|
fd = open(_PATH_TMP, O_TMPFILE | O_RDWR | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR);
|
||||||
|
umask(oldmask);
|
||||||
|
if (-1 == fd)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
fp = fdopen(fd, "w+");
|
||||||
|
#else
|
||||||
fp = tmpfile();
|
fp = tmpfile();
|
||||||
|
#endif
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user