From 9896c26c7e68692ab0c4e52b7d80bbd6916aa0e7 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 17 Apr 2018 13:49:19 -0400 Subject: [PATCH] Silence some trivial clang-analyzer/coverity complaints. One minor memory leak in /usr/bin/efivar, a couple of places where the analyzers make assumptions without being able to figure out the data flow. Signed-off-by: Peter Jones --- src/dp-message.c | 7 +++++++ src/efivar.c | 22 ++++++++++++++++++++-- src/linux.c | 13 +++++++++++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/dp-message.c b/src/dp-message.c index becfbc8..8f3b6d6 100644 --- a/src/dp-message.c +++ b/src/dp-message.c @@ -83,9 +83,16 @@ format_ipv6_addr_helper(char *buf, size_t size, const char *dp_type, if (this_zero_block_size > largest_zero_block_size) { largest_zero_block_size = this_zero_block_size; largest_zero_block_offset = this_zero_block_offset; + /* + * clang-analyzer hates these because they're the last use, + * and they don't believe in writing code so that bugs won't + * be introduced later... + */ +#if 0 this_zero_block_size = 0; this_zero_block_offset = -1; in_zero_block = 0; +#endif } if (largest_zero_block_size == 1) largest_zero_block_offset = -1; diff --git a/src/efivar.c b/src/efivar.c index 6ec009f..09e9ec3 100644 --- a/src/efivar.c +++ b/src/efivar.c @@ -175,7 +175,7 @@ bad_name: static void show_variable(char *guid_name, int display_type) { - efi_guid_t guid; + efi_guid_t guid = efi_guid_empty; char *name = NULL; int rc; @@ -184,6 +184,11 @@ show_variable(char *guid_name, int display_type) uint32_t attributes; parse_name(guid_name, &name, &guid); + if (!name || efi_guid_is_empty(&guid)) { + fprintf(stderr, "efivar: could not parse variable name.\n"); + show_errors(); + exit(1); + } errno = 0; rc = efi_get_variable(guid, name, &data, &data_size, &attributes); @@ -252,13 +257,17 @@ show_variable(char *guid_name, int display_type) } printf("\n"); } + + free(name); + if (data) + free(data); } static void edit_variable(const char *guid_name, void *data, size_t data_size, uint32_t attrib, int edit_type) { - efi_guid_t guid; + efi_guid_t guid = efi_guid_empty; char *name = NULL; int rc; uint8_t *old_data = NULL; @@ -266,6 +275,11 @@ edit_variable(const char *guid_name, void *data, size_t data_size, uint32_t old_attributes = 0; parse_name(guid_name, &name, &guid); + if (!name || efi_guid_is_empty(&guid)) { + fprintf(stderr, "efivar: could not parse variable name.\n"); + show_errors(); + exit(1); + } rc = efi_get_variable(guid, name, &old_data, &old_data_size, &old_attributes); @@ -289,6 +303,10 @@ edit_variable(const char *guid_name, void *data, size_t data_size, break; } + free(name); + if (old_data) + free(old_data); + if (rc < 0) { fprintf(stderr, "efivar: %m\n"); show_errors(); diff --git a/src/linux.c b/src/linux.c index 355d7f2..b445cf8 100644 --- a/src/linux.c +++ b/src/linux.c @@ -971,7 +971,12 @@ make_blockdev_path(uint8_t *buf, ssize_t size, struct disk_info *info) &linksz, info); if (rc < 0) return -1; - loff += linksz; + /* + * clang-analyzer complains about this because they + * don't believe in writing code to avoid introducing + * bugs later. + */ + // loff += linksz; off += sz; found = 1; } @@ -1151,7 +1156,11 @@ make_net_pci_path(uint8_t *buf, ssize_t size, const char * const ifname) if (sz < 0) return -1; off += sz; - loff += tmplsz; + /* + * clang-analyzer complains about this because they don't believe in + * writing code to avoid introducing bugs later. + */ + //loff += tmplsz; return off; } -- 2.11.0