summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKota Tsuyuzaki <bloodeagle40234@gmail.com>2015-03-30 10:55:09 +0900
committerKota Tsuyuzaki <bloodeagle40234@gmail.com>2015-03-30 11:01:56 +0900
commit309d7f1e4754ac448d8b098bd36287fa37a77475 (patch)
tree34045ca4d57df38d8a0a70e4b7f7389cb5280714 /src
parentc10ec8a255eaca5c8637a46c3be4f22c707675c7 (diff)
downloadliberasurecode-309d7f1e4754ac448d8b098bd36287fa37a77475.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/erasurecode.c5
-rw-r--r--src/erasurecode_preprocessing.c3
2 files changed, 4 insertions, 4 deletions
diff --git a/src/erasurecode.c b/src/erasurecode.c
index 1544ab7..2c6a30b 100644
--- a/src/erasurecode.c
+++ b/src/erasurecode.c
@@ -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;
}
diff --git a/src/erasurecode_preprocessing.c b/src/erasurecode_preprocessing.c
index a9a7b55..d8da1f6 100644
--- a/src/erasurecode_preprocessing.c
+++ b/src/erasurecode_preprocessing.c
@@ -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 {