summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2011-12-16 11:13:55 -0500
committerStephen Gallagher <sgallagh@redhat.com>2011-12-19 11:38:35 -0500
commit69420a154fc9fb8b04f437125a6a0604b26b1292 (patch)
tree4b8e118a394baa2cc0ceeaeadbd04d12db973ef7 /src/tests
parent05113318e280904f2a1ce3721b8d6504afd7e7df (diff)
downloadsssd-69420a154fc9fb8b04f437125a6a0604b26b1292.tar.gz
sssd-69420a154fc9fb8b04f437125a6a0604b26b1292.tar.xz
sssd-69420a154fc9fb8b04f437125a6a0604b26b1292.zip
Securely set umask when using mkstemp
Coverity 12394, 12395, 12396, 12397 and 12398
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/check_and_open-tests.c4
-rw-r--r--src/tests/debug-tests.c8
2 files changed, 12 insertions, 0 deletions
diff --git a/src/tests/check_and_open-tests.c b/src/tests/check_and_open-tests.c
index 8e1bc9880..6ff40d0fa 100644
--- a/src/tests/check_and_open-tests.c
+++ b/src/tests/check_and_open-tests.c
@@ -43,10 +43,14 @@ int fd;
void setup_check_and_open(void)
{
int ret;
+ mode_t old_umask;
filename = strdup(FILENAME_TEMPLATE);
fail_unless(filename != NULL, "strdup failed");
+
+ old_umask = umask(077);
ret = mkstemp(filename);
+ umask(old_umask);
fail_unless(ret != -1, "mkstemp failed [%d][%s]", errno, strerror(errno));
close(ret);
diff --git a/src/tests/debug-tests.c b/src/tests/debug-tests.c
index 8a338fb5f..40dd2e98b 100644
--- a/src/tests/debug-tests.c
+++ b/src/tests/debug-tests.c
@@ -191,10 +191,14 @@ int test_helper_debug_check_message(int level, int msgmode)
int fd;
int ret;
int _errno = 0;
+ mode_t old_umask;
FILE *file = NULL;
strncpy(filename, "sssd_debug_tests.XXXXXX", 24);
+
+ old_umask = umask(077);
fd = mkstemp(filename);
+ umask(old_umask);
if (fd == -1) {
_errno = errno;
talloc_free(ctx);
@@ -331,10 +335,14 @@ int test_helper_debug_is_empty_message(int level, int msgmode)
int filesize;
int ret;
int _errno = 0;
+ mode_t old_umask;
FILE *file;
strncpy(filename, "sssd_debug_tests.XXXXXX", 24);
+
+ old_umask = umask(077);
fd = mkstemp(filename);
+ umask(old_umask);
if (fd == -1) {
return DEBUG_TEST_ERROR;
}