From ab7f0e0528791f466f36fa7409f75db1dca76f2d Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 1 Apr 2022 09:32:43 -0400 Subject: [PATCH] Fix error checking in imginfo imginfo was checking fread when it should have been checking number of records. --- confluent_osdeploy/utils/confluent_imginfo.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/confluent_osdeploy/utils/confluent_imginfo.c b/confluent_osdeploy/utils/confluent_imginfo.c index c129fb62..3217479a 100644 --- a/confluent_osdeploy/utils/confluent_imginfo.c +++ b/confluent_osdeploy/utils/confluent_imginfo.c @@ -10,7 +10,7 @@ int read_part(FILE* img, long int imgsize) { uint16_t shortlength; uint32_t length; uint64_t longlength; - if (fread(&shortlength, 2, 1, img) < 2) { + if (fread(&shortlength, 2, 1, img) < 1) { fprintf(stderr, "Error reading section\n"); exit(1); } @@ -21,7 +21,7 @@ int read_part(FILE* img, long int imgsize) { exit(1); } mountpath[shortlength] = 0; - if (fread(&length, 4, 1, img) < 4) { + if (fread(&length, 4, 1, img) < 1) { fprintf(stderr, "Failure reading segment\n"); exit(1); } @@ -30,19 +30,19 @@ int read_part(FILE* img, long int imgsize) { fprintf(stderr, "Error skipping json segment"); exit(1); } - if (fread(&longlength, 8, 1, img) < 8) { // minimum size in bytes + if (fread(&longlength, 8, 1, img) < 1) { // minimum size in bytes fprintf(stderr, "Failure reading segment\n"); exit(1); } longlength = be64toh(longlength); printf("%ld\t", longlength); - if (fread(&longlength, 8, 1, img) < 8) { // default size in bytes + if (fread(&longlength, 8, 1, img) < 1) { // default size in bytes fprintf(stderr, "Error reading segment\n"); exit(1); } longlength = be64toh(longlength); printf("%ld\t", longlength); - if (fread(&shortlength, 2, 1, img) < 2) { // length of filesystem type + if (fread(&shortlength, 2, 1, img) < 1) { // length of filesystem type fprintf(stderr, "Error reading segment\n"); exit(1); } @@ -53,7 +53,7 @@ int read_part(FILE* img, long int imgsize) { exit(1); } fstype[shortlength] = 0; - if (fread(&shortlength, 2, 1, img) < 2) { // length of DEVICE + if (fread(&shortlength, 2, 1, img) < 1) { // length of DEVICE fprintf(stderr, "Error reading segment\n"); exit(1); } @@ -64,7 +64,7 @@ int read_part(FILE* img, long int imgsize) { exit(1); } devpath[shortlength] = 0; - if (fread(&shortlength, 2, 1, img) < 2) { + if (fread(&shortlength, 2, 1, img) < 1) { fprintf(stderr, "Error reading segment\n"); exit(1); } @@ -73,7 +73,7 @@ int read_part(FILE* img, long int imgsize) { fprintf(stderr, "Failure skipping padding\n"); exit(1); } - if (fread(&longlength, 8, 1, img) < 8) { + if (fread(&longlength, 8, 1, img) < 1) { fprintf(stderr, "Error reading section\n"); exit(1); }