static int
add_metadata(struct fwimage_trailer *tr)
{
- struct fwimage_header hdr = {};
+ struct fwimage_header hdr;
tr->type = FWIMAGE_INFO;
tr->size = sizeof(hdr) + sizeof(*tr);
+ memset(&hdr, 0, sizeof(hdr));
trailer_update_crc(tr, &hdr, sizeof(hdr));
fwrite(&hdr, sizeof(hdr), 1, firmware_file);
static int
add_data(const char *name)
{
- struct fwimage_trailer tr = {
- .magic = cpu_to_be32(FWIMAGE_MAGIC),
- .crc32 = ~0,
- };
+ struct fwimage_trailer tr;
int file_len = 0;
int ret = 0;
+ memset(&tr, 0, sizeof(tr));
+
+ tr.crc32 = ~0;
+ tr.magic = cpu_to_be32(FWIMAGE_MAGIC);
+
firmware_file = fopen(name, "r+");
if (!firmware_file) {
msg("Failed to open firmware file\n");
if (ret) {
fflush(firmware_file);
- ftruncate(fileno(firmware_file), file_len);
+ ret = ftruncate(fileno(firmware_file), file_len);
+ if (ret < 0)
+ msg("Error during ftruncate: %m\n");
}
return ret;
remove_tail(dbuf, cur_len);
cur_len = len - cur_len;
- if (cur_len && !dbuf->cur)
+ if (cur_len < 0 || !dbuf->cur)
return 1;
memcpy(dest, dbuf->cur + dbuf->cur_len - cur_len, cur_len);
void *buf;
bool metadata_keep = false;
+ memset(&tr, 0, sizeof(tr));
+
firmware_file = open_file(name, false);
if (!firmware_file) {
msg("Failed to open firmware file\n");
while (1) {
- if (extract_tail(&dbuf, &tr, sizeof(tr)))
+ if (extract_tail(&dbuf, &tr, sizeof(tr))) {
+ msg("unable to extract trailer header\n");
break;
+ }
if (tr.magic != cpu_to_be32(FWIMAGE_MAGIC)) {
msg("Data not found\n");
break;
}
- extract_tail(&dbuf, buf, data_len);
+ if (extract_tail(&dbuf, buf, data_len)) {
+ msg("unable to extract trailer data\n");
+ break;
+ }
if (tr.type == FWIMAGE_SIGNATURE) {
if (!signature_file)
}
}
- if (!ret && truncate_file)
- ftruncate(fileno(firmware_file), dbuf.file_len);
+ if (!ret && truncate_file) {
+ ret = ftruncate(fileno(firmware_file), dbuf.file_len);
+ if (ret < 0) {
+ msg("Error during ftruncate: %m\n");
+ goto out;
+ }
+ }
if (write_truncated) {
if (dbuf.prev)