summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2017-07-13 16:54:20 -0700
committerTim Burke <tim.burke@gmail.com>2017-09-13 20:46:19 +0000
commitcf12c9ca26e4388e383f1aa3c1558d61eda96777 (patch)
treef10d678de7dedc73b675dac246a75833cb4e1917
parent737843e14e7b29b122b7a55b1c1ab777bf83464f (diff)
flat_xor_hd: better validate args
Previously, we'd segfault with args like k=1, m=3, hd=3. Change-Id: I8a1d92f388c54fe4f5b357eaf85a27e6b334df11
Notes
Notes (review): Code-Review+2: Tim Burke <tim@swiftstack.com> Workflow+1: Tim Burke <tim@swiftstack.com> Code-Review+2: Timur Alperovich <timur.alperovich@gmail.com> Workflow+1: Timur Alperovich <timur.alperovich@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 13 Sep 2017 21:33:43 +0000 Reviewed-on: https://review.openstack.org/483610 Project: openstack/liberasurecode Branch: refs/heads/master
-rw-r--r--src/builtin/xor_codes/xor_hd_code.c2
-rw-r--r--test/liberasurecode_test.c23
2 files changed, 24 insertions, 1 deletions
diff --git a/src/builtin/xor_codes/xor_hd_code.c b/src/builtin/xor_codes/xor_hd_code.c
index 5c4d052..9e41ad1 100644
--- a/src/builtin/xor_codes/xor_hd_code.c
+++ b/src/builtin/xor_codes/xor_hd_code.c
@@ -664,7 +664,7 @@ xor_code_t* init_xor_hd_code(int k, int m, int hd)
664 if (k <= 10 && k >= 5) { 664 if (k <= 10 && k >= 5) {
665 is_valid = 1; 665 is_valid = 1;
666 } 666 }
667 } else if (m == 3) { 667 } else if (m == 3 && k == 3) {
668 is_valid = 1; 668 is_valid = 1;
669 } 669 }
670 } 670 }
diff --git a/test/liberasurecode_test.c b/test/liberasurecode_test.c
index f009a2d..b296c9d 100644
--- a/test/liberasurecode_test.c
+++ b/test/liberasurecode_test.c
@@ -1538,6 +1538,28 @@ static void test_jerasure_rs_cauchy_init_failure()
1538 assert(-EBACKENDINITERR == desc); 1538 assert(-EBACKENDINITERR == desc);
1539} 1539}
1540 1540
1541static void test_flat_xor_hd3_init_failure()
1542{
1543 struct ec_args bad_args[] = {
1544 {.k = 1, .m = 5, .hd=3},
1545 {.k = 5, .m = 1, .hd=3},
1546 {.k = 4, .m = 4, .hd=3},
1547 {.k = 1, .m = 3, .hd=3},
1548 {.k = 4, .m = 3, .hd=3},
1549 };
1550
1551 for (int i = 0; i < sizeof(bad_args)/sizeof(bad_args[0]); ++i) {
1552 int desc = -1;
1553 desc = liberasurecode_instance_create(
1554 EC_BACKEND_FLAT_XOR_HD, &bad_args[i]);
1555 if (-EBACKENDNOTAVAIL == desc) {
1556 fprintf (stderr, "Backend library not available!\n");
1557 return;
1558 }
1559 assert(-EBACKENDINITERR == desc);
1560 }
1561}
1562
1541static void test_simple_encode_decode(const ec_backend_id_t be_id, 1563static void test_simple_encode_decode(const ec_backend_id_t be_id,
1542 struct ec_args *args) 1564 struct ec_args *args)
1543{ 1565{
@@ -1821,6 +1843,7 @@ struct testcase testcases[] = {
1821 TEST(test_decode_with_missing_multi_parity, EC_BACKEND_NULL, CHKSUM_NONE), 1843 TEST(test_decode_with_missing_multi_parity, EC_BACKEND_NULL, CHKSUM_NONE),
1822 // Flat XOR backend tests 1844 // Flat XOR backend tests
1823 TEST_SUITE(EC_BACKEND_FLAT_XOR_HD), 1845 TEST_SUITE(EC_BACKEND_FLAT_XOR_HD),
1846 TEST(test_flat_xor_hd3_init_failure, EC_BACKENDS_MAX, 0),
1824 // Jerasure RS Vand backend tests 1847 // Jerasure RS Vand backend tests
1825 TEST_SUITE(EC_BACKEND_JERASURE_RS_VAND), 1848 TEST_SUITE(EC_BACKEND_JERASURE_RS_VAND),
1826 TEST(test_jerasure_rs_vand_simple_encode_decode_over32, EC_BACKENDS_MAX, 0), 1849 TEST(test_jerasure_rs_vand_simple_encode_decode_over32, EC_BACKENDS_MAX, 0),