Skip to content

Commit a9755de

Browse files
committed
Fixed output image size in sign.c
1 parent 9d83b2f commit a9755de

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

tools/keytools/sign.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -660,20 +660,20 @@ int main(int argc, char** argv)
660660
goto exit;
661661
}
662662
fwrite(header, header_idx, 1, f);
663-
664663
/* Copy image to output */
665664
f2 = fopen(image_file, "rb");
666665
pos = 0;
667666
while (pos < image_sz) {
668667
read_sz = image_sz;
669668
if (read_sz > sizeof(buf))
670669
read_sz = sizeof(buf);
671-
fread(buf, read_sz, 1, f2);
672-
fwrite(buf, read_sz, 1, f);
670+
read_sz = fread(buf, 1, read_sz, f2);
671+
if ((read_sz == 0) && (feof(f2)))
672+
break;
673+
fwrite(buf, 1, read_sz, f);
673674
pos += read_sz;
674675
}
675676

676-
677677
if (encrypt && encrypt_key_file) {
678678
uint8_t key[32], iv[12];
679679
uint8_t enc_buf[ENC_BLOCK_SIZE];
@@ -696,14 +696,12 @@ int main(int argc, char** argv)
696696
fprintf(stderr, "Open encrypted output file %s: %s\n", encrypt_key_file, strerror(errno));
697697
}
698698
fsize = ftell(f);
699-
printf("size in: %d\n", fsize);
700699
fseek(f, 0, SEEK_SET); /* restart the _signed file from 0 */
701700

702701
wc_Chacha_SetKey(&cha, key, 32);
703702
for (pos = 0; pos < fsize; pos += ENC_BLOCK_SIZE) {
704703
int fread_retval;
705704
fread_retval = fread(buf, 1, ENC_BLOCK_SIZE, f);
706-
printf("pos: %lu ret: %d\n", pos, fread_retval);
707705
if ((fread_retval == 0) && feof(f)) {
708706
break;
709707
}

0 commit comments

Comments
 (0)