Skip to content

Commit

Permalink
modules/kvs/test: Add EOVERFLOW lookup test case
Browse files Browse the repository at this point in the history
  • Loading branch information
chu11 committed Oct 10, 2017
1 parent e97668d commit a1fbc51
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/modules/kvs/test/lookup.c
Expand Up @@ -2,6 +2,7 @@
#include "config.h"
#endif
#include <stdbool.h>
#include <limits.h>
#include <jansson.h>

#include "src/common/libtap/tap.h"
Expand Down Expand Up @@ -620,10 +621,12 @@ void lookup_errors (void) {
json_t *dir;
json_t *dirref_multi;
json_t *valref_multi_bad;
json_t *valref_multi_overflow;
struct cache *cache;
lookup_t *lh;
href_t dirref_ref;
href_t valref_ref;
href_t valref_long_ref;
href_t root_ref;

ok ((cache = cache_create ()) != NULL,
Expand All @@ -634,6 +637,9 @@ void lookup_errors (void) {
* valref_ref
* "abcd"
*
* valref_long_ref
* "long", but invalid length on buffer
*
* dirref_ref
* "val" : val to "bar"
*
Expand All @@ -648,12 +654,21 @@ void lookup_errors (void) {
* "dirref_bad" : dirref to valref_ref
* "valref_bad" : valref to dirref_ref
* "valref_multi_bad" : [ valref_ref, dirref_ref ]
* "valref_multi_overflow" : [ valref_long_ref, valref_long_ref ]
* "dirref_multi" : dirref to [ dirref_ref, dirref_ref ]
*/

blobref_hash ("sha1", "abcd", 4, valref_ref, sizeof (href_t));
cache_insert (cache, valref_ref, cache_entry_create_raw (strdup ("abcd"), 4));

/* achu: Note that I am abusing internal knowledge that cache
* entries blindly store pointers and lengths. Obviously the
* "real" length of the buffer below is length 4, but I'm storing
* a huge number.
*/
blobref_hash ("sha1", "long", 4, valref_long_ref, sizeof (href_t));
cache_insert (cache, valref_long_ref, cache_entry_create_raw (strdup ("long"), INT_MAX - 32));

dirref = treeobj_create_dir ();
treeobj_insert_entry (dirref, "val", treeobj_create_val ("bar", 3));
kvs_util_json_hash ("sha1", dirref, dirref_ref);
Expand All @@ -677,6 +692,10 @@ void lookup_errors (void) {
treeobj_append_blobref (valref_multi_bad, dirref_ref);
treeobj_insert_entry (root, "valref_multi_bad", valref_multi_bad);

valref_multi_overflow = treeobj_create_valref (valref_long_ref);
treeobj_append_blobref (valref_multi_overflow, valref_long_ref);
treeobj_insert_entry (root, "valref_multi_overflow", valref_multi_overflow);

dirref_multi = treeobj_create_dirref (dirref_ref);
treeobj_append_blobref (dirref_multi, dirref_ref);

Expand Down Expand Up @@ -887,6 +906,19 @@ void lookup_errors (void) {
"lookup_create on valref_multi_bad");
check (lh, EPERM, NULL, "lookup valref_multi_bad");

/* Lookup a valref multiple blobref that points to buffers that will
* over int, should get EOVERFLOW.
*/
ok ((lh = lookup_create (cache,
1,
root_ref,
root_ref,
"valref_multi_overflow",
NULL,
0)) != NULL,
"lookup_create on valref_multi_overflow");
check (lh, EOVERFLOW, NULL, "lookup valref_multi_overflow");

/* Lookup with an invalid root_ref, should get EINVAL */
ok ((lh = lookup_create (cache,
1,
Expand Down

0 comments on commit a1fbc51

Please sign in to comment.