Thanks: Eric Blake for reporting the bug.
---
filters/offset/offset.c | 4 +++-
filters/partition/partition.c | 4 +++-
filters/truncate/truncate.c | 8 +++++++-
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/filters/offset/offset.c b/filters/offset/offset.c
index 24ccb4c..633a1c7 100644
--- a/filters/offset/offset.c
+++ b/filters/offset/offset.c
@@ -156,8 +156,10 @@ offset_extents (struct nbdkit_next_ops *next_ops, void *nxdata,
for (i = 0; i < nbdkit_extents_count (extents2); ++i) {
e = nbdkit_get_extent (extents2, i);
e.offset -= offset;
- if (nbdkit_add_extent (extents, e.offset, e.length, e.type) == -1)
+ if (nbdkit_add_extent (extents, e.offset, e.length, e.type) == -1) {
+ *err = errno;
return -1;
+ }
}
return 0;
}
diff --git a/filters/partition/partition.c b/filters/partition/partition.c
index a89dbec..a635df8 100644
--- a/filters/partition/partition.c
+++ b/filters/partition/partition.c
@@ -246,8 +246,10 @@ partition_extents (struct nbdkit_next_ops *next_ops, void *nxdata,
for (i = 0; i < nbdkit_extents_count (extents2); ++i) {
e = nbdkit_get_extent (extents2, i);
e.offset -= h->offset;
- if (nbdkit_add_extent (extents, e.offset, e.length, e.type) == -1)
+ if (nbdkit_add_extent (extents, e.offset, e.length, e.type) == -1) {
+ *err = errno;
return -1;
+ }
}
return 0;
}
diff --git a/filters/truncate/truncate.c b/filters/truncate/truncate.c
index 076ae22..0c5dedb 100644
--- a/filters/truncate/truncate.c
+++ b/filters/truncate/truncate.c
@@ -319,6 +319,10 @@ truncate_extents (struct nbdkit_next_ops *next_ops, void *nxdata,
* returned data to the original array.
*/
extents2 = nbdkit_extents_new (offset, real_size_copy);
+ if (extents2 == NULL) {
+ *err = errno;
+ return -1;
+ }
if (offset + count <= real_size_copy)
n = count;
else
@@ -329,8 +333,10 @@ truncate_extents (struct nbdkit_next_ops *next_ops, void *nxdata,
for (i = 0; i < nbdkit_extents_count (extents2); ++i) {
struct nbdkit_extent e = nbdkit_get_extent (extents2, i);
- if (nbdkit_add_extent (extents, e.offset, e.length, e.type) == -1)
+ if (nbdkit_add_extent (extents, e.offset, e.length, e.type) == -1) {
+ *err = errno;
return -1;
+ }
}
return 0;
--
2.20.1