File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3737#include <stdbool.h>
3838#include <sys/prctl.h>
3939#include <sys/resource.h>
40+ #include <sys/stat.h>
4041#if defined _WITH_LVS_ || defined _HAVE_LIBIPSET_
4142#include <sys/wait.h>
4243#endif
4344#ifdef _WITH_PERF_
4445#include <stdio.h>
4546#include <sys/types.h>
46- #include <sys/stat.h>
4747#include <sys/epoll.h>
4848#include <sys/inotify.h>
4949#endif
@@ -1468,8 +1468,23 @@ keepalived_modprobe(const char *mod_name)
14681468void
14691469set_tmp_dir (void )
14701470{
1471- if (!(tmp_dir = getenv ("TMPDIR" )) || tmp_dir [0 ] != '/' )
1472- tmp_dir = KA_TMP_DIR ;
1471+ struct stat statbuf ;
1472+
1473+ /* github-advanced-security identifies this as a high security risk.
1474+ * See https://github.com/acassen/keepalived/pull/2661#discussion_r3778043666
1475+ * https://github.com/acassen/keepalived/security/code-scanning/197
1476+ *
1477+ * Is this really an issue? root can open and write any writeable file.
1478+ */
1479+ if ((tmp_dir = getenv ("TMPDIR" )) && tmp_dir [0 ] == '/' ) {
1480+ /* Check it is a directory */
1481+ if (!stat (tmp_dir , & statbuf ) && S_ISDIR (statbuf .st_mode ))
1482+ return ;
1483+
1484+ log_message (LOG_INFO , "Environment TMPDIR=%s not a directory" , tmp_dir );
1485+ }
1486+
1487+ tmp_dir = KA_TMP_DIR ;
14731488}
14741489
14751490const char *
You can’t perform that action at this time.
0 commit comments