diff options
author | Tim Burke <tim.burke@gmail.com> | 2017-06-08 19:46:25 +0000 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2017-09-13 20:52:30 +0000 |
commit | 082e4799d81149a9f0ca4e9d8afc65e64118fec0 (patch) | |
tree | a146b06aab038b5a0dfdd0181360bdedb6826437 | |
parent | dd31ac647bdfbac0f95025329d96580d5f52fd76 (diff) | |
download | liberasurecode-082e4799d81149a9f0ca4e9d8afc65e64118fec0.tar.gz |
Negative data or parity args are invalid
While we're at it, tighten up some test_create_backend_invalid_args
assertions.
Change-Id: Id6c70cdb2d86580280ededc3ec6ec648c6cb7d57
-rw-r--r-- | src/erasurecode.c | 2 | ||||
-rw-r--r-- | test/liberasurecode_test.c | 36 |
2 files changed, 19 insertions, 19 deletions
diff --git a/src/erasurecode.c b/src/erasurecode.c index d4a06c2..e324365 100644 --- a/src/erasurecode.c +++ b/src/erasurecode.c @@ -273,6 +273,8 @@ int liberasurecode_instance_create(const ec_backend_id_t id, if (id >= EC_BACKENDS_MAX) return -EBACKENDNOTSUPP; + if (args->k < 0 || args->m < 0) + return -EINVALIDPARAMS; if ((args->k + args->m) > EC_MAX_FRAGMENTS) { log_error("Total number of fragments (k + m) must be less than %d\n", EC_MAX_FRAGMENTS); diff --git a/test/liberasurecode_test.c b/test/liberasurecode_test.c index 4791ca9..071889f 100644 --- a/test/liberasurecode_test.c +++ b/test/liberasurecode_test.c @@ -518,32 +518,30 @@ static void test_backend_available_invalid_args() static void test_create_backend_invalid_args() { int desc = liberasurecode_instance_create(-1, &null_args); - if (-EBACKENDNOTAVAIL == desc) { - fprintf (stderr, "Backend library not available!\n"); - return; - } - assert(desc < 0); + assert(-EBACKENDNOTSUPP == desc); + desc = liberasurecode_instance_create(EC_BACKENDS_MAX, &null_args); - if (-EBACKENDNOTAVAIL == desc) { - fprintf (stderr, "Backend library not available!\n"); - return; - } - assert(desc < 0); + assert(-EBACKENDNOTSUPP == desc); + desc = liberasurecode_instance_create(EC_BACKEND_NULL, NULL); - if (-EBACKENDNOTAVAIL == desc) { - fprintf (stderr, "Backend library not available!\n"); - return; - } + assert(-EINVALIDPARAMS == desc); + struct ec_args invalid_args = { .k = 100, .m = 100, }; desc = liberasurecode_instance_create(EC_BACKEND_NULL, &invalid_args); - if (-EBACKENDNOTAVAIL == desc) { - fprintf (stderr, "Backend library not available!\n"); - return; - } - assert(desc < 0); + assert(-EINVALIDPARAMS == desc); + + invalid_args.k = -1; + invalid_args.m = 4; + desc = liberasurecode_instance_create(EC_BACKEND_NULL, &invalid_args); + assert(-EINVALIDPARAMS == desc); + + invalid_args.k = 10; + invalid_args.m = -1; + desc = liberasurecode_instance_create(EC_BACKEND_NULL, &invalid_args); + assert(-EINVALIDPARAMS == desc); } static void test_destroy_backend_invalid_args() |