Fix invalid metadata handling

On the current code, get_fragment_partition might touch the
invlid memory area with minus index (that means a invalid header)
and it causes segmentation fault.

This fixes it to handle the minus index as a EBADHEADER and then
no segmentaition fault appeared on the case.
This commit is contained in:
Kota Tsuyuzaki 2015-03-30 10:55:09 +09:00
parent c10ec8a255
commit 309d7f1e47
3 changed files with 6 additions and 5 deletions

View File

@ -566,10 +566,7 @@ int liberasurecode_decode(int desc,
available_fragments, num_fragments,
out_data, out_data_len);
if (ret == -1) {
/* Ignore - not necessarily an error
* (see fragments_to_string() in src/erasurecode_preprocessing.c) */
} else if (ret <= 0) {
if (ret == 0) {
/* We were able to get the original data without decoding! */
goto out;
}

View File

@ -224,6 +224,9 @@ int get_fragment_partition(
*/
for (i = 0; i < num_fragments; i++) {
index = get_fragment_idx(fragments[i]);
if (index < 0){
return -EBADHEADER;
}
if (index < k) {
data[index] = fragments[i];
} else {

View File

@ -434,7 +434,8 @@ static void test_decode_invalid_args()
rc = liberasurecode_decode(desc, avail_frags, num_avail_frags,
strlen(fake_data), 1,
&decoded_data, &decoded_data_len);
assert(rc == -EBADHEADER);
// force_metadata_checks results in EINSUFFFRAGS
assert(rc == -EINSUFFFRAGS);
// test with num_fragments < (k)
num_avail_frags = create_fake_frags_no_meta(&avail_frags, (null_args.k - 1),