Bug fix: Appending partitions 5 to 8 caused damaged ISO filesystems if not for SUN disk label

This commit is contained in:
Thomas Schmitt 2019-01-15 16:26:56 +01:00
parent 4064a7e0ee
commit a1e75003b5
3 changed files with 40 additions and 19 deletions

View File

@ -4601,13 +4601,13 @@ ex: /* LIBISO_ALLOC_MEM failed */
} }
/* Obtains start and end number of appended partition range and returns /* Determines the range of valid partition numbers depending on partition
the number of valid entries in the list of appended partitions. table type.
*/ */
int iso_count_appended_partitions(Ecma119Image *target, void iso_tell_max_part_range(Ecma119Image *target,
int *first_partition, int *last_partition) int *first_partition, int *last_partition)
{ {
int sa_type, i, count= 0; int sa_type;
sa_type = (target->system_area_options >> 2) & 0x3f; sa_type = (target->system_area_options >> 2) & 0x3f;
if (sa_type == 3) { /* SUN Disk Label */ if (sa_type == 3) { /* SUN Disk Label */
@ -4617,6 +4617,18 @@ int iso_count_appended_partitions(Ecma119Image *target,
*first_partition = 1; *first_partition = 1;
*last_partition = 4; *last_partition = 4;
} }
}
/* Obtains start and end number of appended partition range and returns
the number of valid entries in the list of appended partitions.
*/
int iso_count_appended_partitions(Ecma119Image *target,
int *first_partition, int *last_partition)
{
int i, count= 0;
iso_tell_max_part_range(target, first_partition, last_partition);
for (i = *first_partition - 1; i <= *last_partition - 1; i++) { for (i = *first_partition - 1; i <= *last_partition - 1; i++) {
if (target->opts->appended_partitions[i] == NULL) if (target->opts->appended_partitions[i] == NULL)
continue; continue;

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2007 Vreixo Formoso * Copyright (c) 2007 Vreixo Formoso
* Copyright (c) 2009 - 2018 Thomas Schmitt * Copyright (c) 2009 - 2019 Thomas Schmitt
* *
* This file is part of the libisofs project; you can redistribute it and/or * This file is part of the libisofs project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2 * modify it under the terms of the GNU General Public License version 2
@ -1055,4 +1055,10 @@ int iso_interval_reader_start_size(Ecma119Image *t, char *path,
int iso_count_appended_partitions(Ecma119Image *target, int iso_count_appended_partitions(Ecma119Image *target,
int *first_partition, int *last_partition); int *first_partition, int *last_partition);
/* Determines the range of valid partition numbers depending on partition
table type.
*/
void iso_tell_max_part_range(Ecma119Image *target,
int *first_partition, int *last_partition);
#endif /*LIBISO_ECMA119_H_*/ #endif /*LIBISO_ECMA119_H_*/

View File

@ -153,8 +153,10 @@ static int compute_partition_size(Ecma119Image *t, char *disk_path,
int iso_compute_append_partitions(Ecma119Image *t, int flag) int iso_compute_append_partitions(Ecma119Image *t, int flag)
{ {
int ret, i, sa_type, cyl_align, cyl_size = 0; int ret, i, sa_type, cyl_align, cyl_size = 0;
int first_partition, last_partition;
uint32_t pos, size, add_pos = 0; uint32_t pos, size, add_pos = 0;
off_t start_byte, byte_count; off_t start_byte, byte_count;
char msg[80];
sa_type = (t->system_area_options >> 2) & 0x3f; sa_type = (t->system_area_options >> 2) & 0x3f;
cyl_align = (t->system_area_options >> 8) & 0x3; cyl_align = (t->system_area_options >> 8) & 0x3;
@ -176,11 +178,20 @@ int iso_compute_append_partitions(Ecma119Image *t, int flag)
#endif #endif
iso_tell_max_part_range(t, &first_partition, &last_partition);
for (i = 0; i < ISO_MAX_PARTITIONS; i++) { for (i = 0; i < ISO_MAX_PARTITIONS; i++) {
if (t->opts->appended_partitions[i] == NULL) if (t->opts->appended_partitions[i] == NULL)
continue; continue;
if (t->opts->appended_partitions[i][0] == 0) if (t->opts->appended_partitions[i][0] == 0)
continue; continue;
if (i + 1 > last_partition || i + 1 < first_partition) {
sprintf(msg,
"Partition number %d of appended partition is out of range [%d - %d]",
i + 1, first_partition, last_partition);
iso_msgs_submit(0, msg, 0, "FAILURE", 0);
return ISO_BAD_PARTITION_NO;
}
ret = compute_partition_size(t, t->opts->appended_partitions[i], &size, ret = compute_partition_size(t, t->opts->appended_partitions[i], &size,
t->opts->appended_part_flags[i]); t->opts->appended_part_flags[i]);
if (ret < 0) if (ret < 0)
@ -1862,10 +1873,8 @@ int iso_write_system_area(Ecma119Image *t, uint8_t *buf)
memset(buf, 0, 16 * BLOCK_SIZE); memset(buf, 0, 16 * BLOCK_SIZE);
sa_type = (t->system_area_options >> 2) & 0x3f; sa_type = (t->system_area_options >> 2) & 0x3f;
if (sa_type == 3) {
first_partition = 2; iso_tell_max_part_range(t, &first_partition, &last_partition);
last_partition = 8;
}
for (i = first_partition - 1; i <= last_partition - 1; i++) for (i = first_partition - 1; i <= last_partition - 1; i++)
if (t->opts->appended_partitions[i] != NULL) { if (t->opts->appended_partitions[i] != NULL) {
will_append = 1; will_append = 1;
@ -3190,20 +3199,14 @@ static int partappend_writer_write_vol_desc(IsoImageWriter *writer)
static int partappend_writer_write_data(IsoImageWriter *writer) static int partappend_writer_write_data(IsoImageWriter *writer)
{ {
Ecma119Image *target; Ecma119Image *target;
int res, first_partition = 1, last_partition = 0, sa_type; int res, first_partition = 1, last_partition = 0;
int i; int i;
target = writer->target; target = writer->target;
/* Append partition data */ /* Append partition data */
sa_type = (target->system_area_options >> 2) & 0x3f; iso_tell_max_part_range(target, &first_partition, &last_partition);
if (sa_type == 0) { /* MBR */
first_partition = 1;
last_partition = 4;
} else if (sa_type == 3) { /* SUN Disk Label */
first_partition = 2;
last_partition = 8;
}
for (i = first_partition - 1; i <= last_partition - 1; i++) { for (i = first_partition - 1; i <= last_partition - 1; i++) {
if (target->opts->appended_partitions[i] == NULL) if (target->opts->appended_partitions[i] == NULL)
continue; continue;