]> git.proxmox.com Git - swtpm.git/commitdiff
swtpm_cert: Free variable before parsing it to avoid memory leak (Coverity)
authorStefan Berger <stefanb@linux.ibm.com>
Wed, 25 May 2022 19:09:47 +0000 (15:09 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Wed, 25 May 2022 22:54:58 +0000 (18:54 -0400)
Avoid memory leaks if one of the parameters --modulus, --ecc-x,
or --ecc-y was passed multiple times by freeing the previously
parsed value.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
src/swtpm_cert/ek-cert.c

index 391699ff590ee6a82df9ad737432a8e4d05550a9..b66e1a41fff8f6334c0663df0e8d1bfc0b28fda7 100644 (file)
@@ -1096,16 +1096,19 @@ main(int argc, char *argv[])
             pubkey_filename = optarg;
             break;
         case 'm': /* --modulus */
+            free(modulus_bin);
             if (!(modulus_bin = hex_str_to_bin(optarg, &modulus_len))) {
                 goto cleanup;
             }
             break;
         case 'x': /* --ecc-x */
+            free(ecc_x_bin);
             if (!(ecc_x_bin = hex_str_to_bin(optarg, &ecc_x_len))) {
                 goto cleanup;
             }
             break;
         case 'y': /* --ecc-y */
+            free(ecc_y_bin);
             if (!(ecc_y_bin = hex_str_to_bin(optarg, &ecc_y_len))) {
                 goto cleanup;
             }