From 028f9275d3812b0c70a6d50abbc7516242b80641 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sat, 26 Aug 2017 11:47:14 +0200 Subject: [PATCH] Throw error if imported_iso interval would be overwritten by multi-session --- libisofs/ecma119.c | 14 +++++++++----- libisofs/libisofs.h | 4 ++++ libisofs/messages.c | 2 ++ libisofs/system_area.c | 2 ++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/libisofs/ecma119.c b/libisofs/ecma119.c index 106ec62..2a9ee6a 100644 --- a/libisofs/ecma119.c +++ b/libisofs/ecma119.c @@ -2013,12 +2013,11 @@ int iso_interval_reader_keep(Ecma119Image *target, if (!target->opts->appendable) return 0; + /* --- From here on return either 1 or <0 --- */ + /* multi-session write offset must be larger than interval end */ if (target->opts->ms_block <= ivr->end_byte / BLOCK_SIZE) - - /* >>> ??? return error ??? */ - - return 0; + return ISO_MULTI_OVER_IMPORTED; return 1; } @@ -2036,6 +2035,8 @@ int iso_interval_reader_start_size(Ecma119Image *t, char *path, return ret; *start_byte = ivr->start_byte; keep = iso_interval_reader_keep(t, ivr, 0); + if (keep < 0) + return(keep); iso_interval_reader_destroy(&ivr, 0); return ISO_SUCCESS + (keep > 0); } @@ -2066,7 +2067,10 @@ int iso_write_partition_file(Ecma119Image *target, char *path, &ivr, &byte_count, 0); if (ret < 0) goto ex; - if (iso_interval_reader_keep(target, ivr, 0)) { + ret = iso_interval_reader_keep(target, ivr, 0); + if (ret < 0) + goto ex; + if (ret > 0) { /* From imported_iso and for add-on session. Leave it in place. */ ret = ISO_SUCCESS; goto ex; diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 8c6977a..090d602 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -8887,6 +8887,10 @@ int iso_conv_name_chars(IsoWriteOpts *opts, char *name, size_t name_len, (FAILURE, HIGH, -419) */ #define ISO_SUSP_WRONG_CE_SIZE 0xE830FE5D +/** Multi-session would overwrite imported_iso interval + (FAILURE, HIGH, -420) */ +#define ISO_MULTI_OVER_IMPORTED 0xE830FE5C + /* Internal developer note: Place new error codes directly above this comment. diff --git a/libisofs/messages.c b/libisofs/messages.c index 84d4cc0..a498a59 100644 --- a/libisofs/messages.c +++ b/libisofs/messages.c @@ -551,6 +551,8 @@ const char *iso_error_to_msg(int errcode) return "Unable to obtain root directory"; case ISO_SUSP_WRONG_CE_SIZE: return "Zero sized, oversized, or mislocated SUSP CE area found"; + case ISO_MULTI_OVER_IMPORTED: + return "Multi-session would overwrite imported_iso interval"; default: return "Unknown error"; } diff --git a/libisofs/system_area.c b/libisofs/system_area.c index f5a3b6c..1bac1a2 100644 --- a/libisofs/system_area.c +++ b/libisofs/system_area.c @@ -129,6 +129,8 @@ static int compute_partition_size(Ecma119Image *t, char *disk_path, *size = (byte_count + BLOCK_SIZE - 1) / BLOCK_SIZE; keep = iso_interval_reader_keep(t, ivr, 0); iso_interval_reader_destroy(&ivr, 0); + if (keep < 0) + return keep; return ISO_SUCCESS + (keep > 0); }