fixed unnecessary checks of unsigned variable and endless loop/array out-of-bounds access in src/mess/tools/imgtool/modules/bml3.c (nw)

This commit is contained in:
Oliver Stöneberg 2013-09-16 15:15:57 +00:00
parent 1db1801a5b
commit c96cf34c5b

View File

@ -394,9 +394,11 @@ static imgtoolerr_t get_file_size(struct bml3_dirent *ent, imgtool_image *img, c
ferr = read_granule(img, granule_list->granules[granule_list->granule_count-1], info->sector_size * (granule_list->last_granule_sectors - 1), info->sector_size, buf);
if (ferr)
return imgtool_floppy_error(ferr);
for (last_sector_bytes = info->sector_size - 1; last_sector_bytes >= 0; last_sector_bytes--) {
for (last_sector_bytes = info->sector_size - 1; ; last_sector_bytes--) {
if (buf[last_sector_bytes] != 0)
break;
if (last_sector_bytes == 0)
break;
}
if (buf[last_sector_bytes] != 0x1a) {
last_sector_bytes++;
@ -409,7 +411,7 @@ static imgtoolerr_t get_file_size(struct bml3_dirent *ent, imgtool_image *img, c
}
// TODO is it valid for last_sector_bytes == 0?
if (last_sector_bytes < 0 || last_sector_bytes > info->sector_size) {
if (last_sector_bytes > info->sector_size) {
return IMGTOOLERR_CORRUPTIMAGE;
}
*size += last_sector_bytes;