Skip to content

Commit

Permalink
common/libkvs: Add error check
Browse files Browse the repository at this point in the history
Add input error check ot treeobj_create_symlink() with appropriate
unit test.

rebase: move earlier in commit series
  • Loading branch information
chu11 committed Oct 31, 2017
1 parent 4c44423 commit fcb92f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/common/libkvs/test/treeobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@ void test_symlink (void)
{
json_t *o, *data;

ok (treeobj_create_symlink (NULL) == NULL
&& errno == EINVAL,
"treeobj_create_symlink fails on bad input with EINVAL");
o = treeobj_create_symlink ("a.b.c");
ok (o != NULL,
"treeobj_create_symlink works");
Expand Down
5 changes: 5 additions & 0 deletions src/common/libkvs/treeobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ json_t *treeobj_create_symlink (const char *target)
{
json_t *obj;

if (!target) {
errno = EINVAL;
return NULL;
}

if (!(obj = json_pack ("{s:i s:s s:s}", "ver", treeobj_version,
"type", "symlink",
"data", target))) {
Expand Down

0 comments on commit fcb92f4

Please sign in to comment.