mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
Replace insecure tmpfile() with mkstemp() based local tempfile()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
c6a9fa3b98
commit
162b394726
3 files changed
+24
-1
No files matched your search
@@ -179,7 +179,7 @@ int run_interactive(char *cmd, char *fmt, ...)
|
||||
}
|
||||
|
||||
/* Redirect output from cmd to a tempfile */
|
||||
fp = tmpfile();
|
||||
fp = tempfile();
|
||||
if (fp && !debug) {
|
||||
oldout = dup(STDOUT_FILENO);
|
||||
olderr = dup(STDERR_FILENO);
|
||||
|
||||
@@ -126,6 +126,27 @@ int atonum(char *str)
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* tempfile - A secure tmpfile() replacement
|
||||
*
|
||||
* This is the secure replacement for tmpfile() that does not exist in GLIBC.
|
||||
* The function uses mkstemp() for security.
|
||||
*
|
||||
* Returns:
|
||||
* An open %FILE pointer, or %NULL on error.
|
||||
*/
|
||||
FILE *tempfile(void)
|
||||
{
|
||||
int fd;
|
||||
char *template = "/tmp/finit.XXXXXX";
|
||||
|
||||
fd = mkstemp(template);
|
||||
if (-1 == fd)
|
||||
return NULL;
|
||||
|
||||
return fdopen(fd, "rw");
|
||||
}
|
||||
|
||||
static int encode(int lvl)
|
||||
{
|
||||
if (!lvl) return 0;
|
||||
|
||||
Reference in new issue
Block a user