]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: make fdisk_partition_to_string() more robust [coverity scan]
authorKarel Zak <kzak@redhat.com>
Thu, 29 Jan 2015 09:49:51 +0000 (10:49 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 29 Jan 2015 09:49:51 +0000 (10:49 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/partition.c

index ba9f597a35d86066289ec8d9bfd605e5ff24e59b..9a02993c30fdeb2bd9882ca31c5dd359baa08c67 100644 (file)
@@ -661,7 +661,7 @@ int fdisk_partition_to_string(struct fdisk_partition *pa,
        int rc = 0;
        uint64_t x;
 
-       if (!pa || !cxt)
+       if (!pa || !cxt || !data)
                return -EINVAL;
 
        switch (id) {
@@ -762,13 +762,16 @@ int fdisk_partition_to_string(struct fdisk_partition *pa,
                return -EINVAL;
        }
 
-       if (rc < 0)
+       if (rc < 0) {
                rc = -ENOMEM;
-       else if (rc > 0)
+               free(p);
+               p = NULL;
+
+       } else if (rc > 0)
                rc = 0;
 
-       if (data)
-               *data = p;
+       *data = p;
+
        return rc;
 }