OSDN Git Service

Silence some trivial clang-analyzer/coverity complaints.
authorPeter Jones <pjones@redhat.com>
Tue, 17 Apr 2018 17:49:19 +0000 (13:49 -0400)
committerPeter Jones <pjones@redhat.com>
Tue, 17 Apr 2018 18:08:40 +0000 (14:08 -0400)
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 <pjones@redhat.com>
src/dp-message.c
src/efivar.c
src/linux.c

index becfbc8..8f3b6d6 100644 (file)
@@ -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;
index 6ec009f..09e9ec3 100644 (file)
@@ -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();
index 355d7f2..b445cf8 100644 (file)
@@ -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;
 }