summaryrefslogtreecommitdiff
path: root/src/lib/ssm
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/ssm')
-rw-r--r--src/lib/ssm/pool.c10
-rw-r--r--src/lib/ssm/tests/pool_test.c57
2 files changed, 44 insertions, 23 deletions
diff --git a/src/lib/ssm/pool.c b/src/lib/ssm/pool.c
index a388742d..5537d723 100644
--- a/src/lib/ssm/pool.c
+++ b/src/lib/ssm/pool.c
@@ -476,7 +476,6 @@ static ssize_t alloc_from_sc_b(struct ssm_pool * pool,
/* Generate pool filename: uid=0 for GSPP, uid>0 for PUP */
static char * pool_filename(uid_t uid)
{
- char * str;
char base[64];
if (IS_GSPP(uid))
@@ -484,9 +483,7 @@ static char * pool_filename(uid_t uid)
else
snprintf(base, sizeof(base), SSM_PUP_NAME_FMT, (int) uid);
- str = strdup(base);
-
- return str;
+ return strdup(base);
}
void ssm_pool_close(struct ssm_pool * pool)
@@ -527,7 +524,6 @@ void ssm_pool_destroy(struct ssm_pool * pool)
}
#define MM_FLAGS (PROT_READ | PROT_WRITE)
-
static struct ssm_pool * __pool_create(const char * name,
int flags,
uid_t uid,
@@ -554,9 +550,7 @@ static struct ssm_pool * __pool_create(const char * name,
if (flags & O_CREAT) {
if (ftruncate(fd, (off_t) file_size) < 0)
goto fail_truncate;
- if (uid != geteuid())
- (void) fchown(fd, uid, gid);
- if (fchmod(fd, mode) < 0)
+ if (uid != geteuid() && fchown(fd, uid, gid) < 0)
goto fail_truncate;
}
diff --git a/src/lib/ssm/tests/pool_test.c b/src/lib/ssm/tests/pool_test.c
index 87d4d71c..ce0c30c2 100644
--- a/src/lib/ssm/tests/pool_test.c
+++ b/src/lib/ssm/tests/pool_test.c
@@ -62,9 +62,10 @@ static int test_ssm_pool_basic_allocation(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
-
+ }
ret = ssm_pool_alloc(pool, POOL_256, &ptr, &spb);
if (ret < 0) {
printf("Alloc failed: %zd.\n", ret);
@@ -120,8 +121,10 @@ static int test_ssm_pool_multiple_allocations(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
ret1 = ssm_pool_alloc(pool, POOL_256, &ptr1, &spb1);
ret2 = ssm_pool_alloc(pool, POOL_256, &ptr2, &spb2);
@@ -213,8 +216,10 @@ static int test_ssm_pool_no_fallback_for_large(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
ret = ssm_pool_alloc(pool, POOL_2M, &ptr, &spb);
if (ret >= 0) {
@@ -249,8 +254,10 @@ static int test_ssm_pool_blocking_vs_nonblocking(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
ret = ssm_pool_alloc(pool, POOL_2M, &ptr, &spb);
if (ret != -EMSGSIZE) {
@@ -296,8 +303,10 @@ static int test_ssm_pool_stress_test(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
indices = malloc(100 * sizeof(*indices));
if (indices == NULL) {
@@ -393,8 +402,10 @@ static int test_ssm_pool_open_initializes_ssm(void)
TEST_START();
creator = ssm_pool_create(getuid(), getgid());
- if (creator == NULL)
+ if (creator == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
ret = ssm_pool_alloc(creator, POOL_256, &ptr, &spb);
if (ret < 0) {
@@ -440,8 +451,10 @@ static int test_ssm_pool_bounds_checking(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
ret = ssm_pool_alloc(pool, POOL_256, NULL, &spb);
if (ret < 0) {
@@ -503,8 +516,10 @@ static int test_ssm_pool_inter_process_communication(void)
len = strlen(msg) + 1;
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
rb = ssm_rbuff_create(getpid(), 1);
if (rb == NULL) {
@@ -607,8 +622,10 @@ static int test_ssm_pool_read_operation(void)
len = strlen(data) + 1;
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
idx = ssm_pool_alloc(pool, len, &wptr, &spb);
if (idx < 0) {
@@ -657,8 +674,10 @@ static int test_ssm_pool_mlock_operation(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
ret = ssm_pool_mlock(pool);
if (ret < 0)
@@ -691,8 +710,10 @@ static int test_ssm_pk_buff_operations(void)
dlen = strlen(data);
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
idx = ssm_pool_alloc(pool, POOL_256, &ptr, &spb);
if (idx < 0) {
@@ -796,8 +817,10 @@ static int test_ssm_pool_size_class_boundaries(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
for (i = 0; i < sizeof(sizes) / sizeof(sizes[0]); i++) {
struct ssm_pk_buff * hdr;
@@ -857,8 +880,10 @@ static int test_ssm_pool_exhaustion(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
indices = malloc(2048 * sizeof(*indices));
if (indices == NULL) {
@@ -935,8 +960,10 @@ static int test_ssm_pool_reclaim_orphans(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
my_pid = getpid();