From 9d9d4c2847862adec2f474d4126213c17f98e024 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0tetiar?= Date: Wed, 23 Oct 2019 12:11:47 +0200 Subject: [PATCH] fix possible garbage in unitialized char* struct members MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit scan-build from clang version 9 has reported following issues: crc32.h:44:32: warning: The right operand of '^' is a garbage value val = crc_table[(uint8_t)val ^ *(uint8_t*)buf] ^ (val >> 8); ^ ~~~~~~~~~~~~~~ cppcheck version 1.89 has reported following issues: fwtool.c:260:9: error: Uninitialized variable: dest [uninitvar] memcpy(dest, dbuf->cur + dbuf->cur_len - cur_len, cur_len); ^ fwtool.c:333:27: note: Calling function 'extract_tail', 2nd argument '&tr' value is if (extract_tail(&dbuf, &tr, sizeof(tr))) { ^ Signed-off-by: Petr Å tetiar --- fwtool.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fwtool.c b/fwtool.c index e925b0b..6340db9 100644 --- a/fwtool.c +++ b/fwtool.c @@ -145,11 +145,12 @@ append_trailer(FILE *out, struct fwimage_trailer *tr) 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); @@ -181,13 +182,15 @@ add_signature(struct fwimage_trailer *tr) 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"); @@ -289,6 +292,8 @@ extract_data(const char *name) 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"); -- 2.30.2