diff --git a/src/ext_manifest.c b/src/ext_manifest.c index 9624156..99b77f2 100644 --- a/src/ext_manifest.c +++ b/src/ext_manifest.c @@ -25,7 +25,8 @@ const struct ext_man_header ext_man_template = { static int ext_man_open_file(struct image *image) { /* open extended manifest outfile for writing */ - sprintf(image->out_ext_man_file, "%s.xman", image->out_file); + snprintf(image->out_ext_man_file, sizeof(image->out_ext_man_file), + "%s.xman", image->out_file); unlink(image->out_ext_man_file); image->out_ext_man_fd = fopen(image->out_ext_man_file, "wb"); diff --git a/src/file_simple.c b/src/file_simple.c index 3c34496..50f3f13 100644 --- a/src/file_simple.c +++ b/src/file_simple.c @@ -128,6 +128,11 @@ static int simple_write_module(struct image *image, struct module *module) /* Get the pointer of writing hdr */ ptr_hdr = ftell(image->out_fd); + if (ptr_hdr < 0) { + fprintf(stderr, "error: cant get file position\n"); + return -errno; + } + count = fwrite(&hdr, sizeof(hdr), 1, image->out_fd); if (count != 1) { fprintf(stderr, "error: failed to write section header %d\n", @@ -172,15 +177,28 @@ static int simple_write_module(struct image *image, struct module *module) hdr.size += padding; /* Record current pointer, will set it back after overwriting hdr */ ptr_cur = ftell(image->out_fd); + if (ptr_cur < 0) { + fprintf(stderr, "error: cant get file position\n"); + return -errno; + } /* overwrite hdr */ - fseek(image->out_fd, ptr_hdr, SEEK_SET); + err = fseek(image->out_fd, ptr_hdr, SEEK_SET); + if (err) { + fprintf(stderr, "cant seek %d\n", -errno); + return -errno; + } + count = fwrite(&hdr, sizeof(hdr), 1, image->out_fd); if (count != 1) { fprintf(stderr, "error: failed to write section header %d\n", -errno); return -errno; } - fseek(image->out_fd, ptr_cur, SEEK_SET); + err = fseek(image->out_fd, ptr_cur, SEEK_SET); + if (err) { + fprintf(stderr, "cant seek %d\n", -errno); + return -errno; + } fprintf(stdout, "\n"); /* return padding size */ @@ -324,7 +342,12 @@ int simple_write_firmware(struct image *image) hdr.file_size += ret; } /* overwrite hdr */ - fseek(image->out_fd, 0, SEEK_SET); + ret = fseek(image->out_fd, 0, SEEK_SET); + if (ret) { + fprintf(stderr, "cant seek %d\n", -errno); + return -errno; + } + count = fwrite(&hdr, sizeof(hdr), 1, image->out_fd); if (count != 1) return -errno; diff --git a/src/manifest.c b/src/manifest.c index d3d7f26..7e52efe 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -27,7 +27,8 @@ static int man_open_rom_file(struct image *image) { uint32_t size; - sprintf(image->out_rom_file, "%s.rom", image->out_file); + snprintf(image->out_rom_file, sizeof(image->out_rom_file), + "%s.rom", image->out_file); unlink(image->out_rom_file); size = image->adsp->mem_zones[SOF_FW_BLK_TYPE_ROM].size; @@ -50,7 +51,8 @@ static int man_open_rom_file(struct image *image) static int man_open_unsigned_file(struct image *image) { - sprintf(image->out_unsigned_file, "%s.uns", image->out_file); + snprintf(image->out_unsigned_file, sizeof(image->out_unsigned_file), + "%s.uns", image->out_file); unlink(image->out_unsigned_file); /* open unsigned FW outfile for writing */ @@ -67,7 +69,8 @@ static int man_open_unsigned_file(struct image *image) static int man_open_manifest_file(struct image *image) { /* open manifest outfile for writing */ - sprintf(image->out_man_file, "%s.met", image->out_file); + snprintf(image->out_man_file, sizeof(image->out_man_file), + "%s.met", image->out_file); unlink(image->out_man_file); image->out_man_fd = fopen(image->out_man_file, "wb"); @@ -1361,10 +1364,10 @@ int man_write_fw_v2_5(struct image *image) int verify_image(struct image *image) { FILE *in_file; - int ret, i; + int ret = 0; long size; void *buffer; - size_t read; + size_t read, i; /* is verify supported for target ? */ if (!image->adsp->verify_firmware) { @@ -1432,7 +1435,7 @@ int verify_image(struct image *image) image->verify_file); out: fclose(in_file); - return 0; + return ret; } @@ -1440,7 +1443,8 @@ int resign_image(struct image *image) { int key_size, key_file_size; void *buffer = NULL; - size_t size, read; + size_t read; + int32_t size; FILE *in_file; int ret, i; @@ -1487,7 +1491,7 @@ int resign_image(struct image *image) /* read file into buffer */ read = fread(buffer, 1, size, in_file); if (read != size) { - fprintf(stderr, "error: unable to read %zu bytes from %s err %d\n", + fprintf(stderr, "error: unable to read %d bytes from %s err %d\n", size, image->in_file, errno); ret = errno; goto out; diff --git a/src/rimage.c b/src/rimage.c index c7b112d..f24aed9 100644 --- a/src/rimage.c +++ b/src/rimage.c @@ -160,7 +160,8 @@ int main(int argc, char *argv[]) if (image.in_file) { fprintf(stdout, "going to re-sign\n"); - return resign_image(&image); + ret = resign_image(&image); + goto out; } /* set IMR Type in found machine definition */