diff --git a/src/common/libkvs/test/treeobj.c b/src/common/libkvs/test/treeobj.c index c392d84a6d9f..14f433b69b0c 100644 --- a/src/common/libkvs/test/treeobj.c +++ b/src/common/libkvs/test/treeobj.c @@ -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"); diff --git a/src/common/libkvs/treeobj.c b/src/common/libkvs/treeobj.c index 56026aa731ac..a1d6d977d621 100644 --- a/src/common/libkvs/treeobj.c +++ b/src/common/libkvs/treeobj.c @@ -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))) {