Skip to content

Commit

Permalink
modules/kvs: Add fence_create() input check
Browse files Browse the repository at this point in the history
Check that name is not NULL and nprocs is > 0.
  • Loading branch information
chu11 committed Feb 20, 2018
1 parent c101d1d commit 134370e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/modules/kvs/fence.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ void fence_destroy (fence_t *f)

fence_t *fence_create (const char *name, int nprocs, int flags)
{
fence_t *f;
fence_t *f = NULL;
json_t *s = NULL;
int saved_errno;

if (!name || nprocs <= 0) {
saved_errno = EINVAL;
goto error;
}
if (!(f = calloc (1, sizeof (*f)))
|| !(f->ops = json_array ())
|| !(f->names = json_array ())
Expand All @@ -74,16 +78,14 @@ fence_t *fence_create (const char *name, int nprocs, int flags)
f->nprocs = nprocs;
f->flags = flags;
f->aux_int = 0;
if (name) {
if (!(s = json_string (name))) {
saved_errno = ENOMEM;
goto error;
}
if (json_array_append_new (f->names, s) < 0) {
json_decref (s);
saved_errno = ENOMEM;
goto error;
}
if (!(s = json_string (name))) {
saved_errno = ENOMEM;
goto error;
}
if (json_array_append_new (f->names, s) < 0) {
json_decref (s);
saved_errno = ENOMEM;
goto error;
}

return f;
Expand Down
3 changes: 3 additions & 0 deletions src/modules/kvs/test/fence.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ void basic_api_tests (void)
flux_msg_t *request;
int count = 0;

ok (fence_create (NULL, 0, 0) == NULL,
"fence_create fails on bad input");

ok ((f = fence_create ("foo", 1, 3)) != NULL,
"fence_create works");

Expand Down

0 comments on commit 134370e

Please sign in to comment.