examples/fips_validation: fix crash on allocation failure
authorCiara Power <ciara.power@intel.com>
Fri, 30 Oct 2020 15:37:00 +0000 (15:37 +0000)
committerDavid Marchand <david.marchand@redhat.com>
Sat, 31 Oct 2020 17:00:03 +0000 (18:00 +0100)
The return value was not being checked when calling the
get_writeback_data function in the AES test case. On failure, this led
to a NULL dereference when using memcpy later. The return value is now
checked to avoid this NULL dereference.

Coverity issue: 363463
Fixes: 952e10cdad5e ("examples/fips_validation: support scatter gather list")

Signed-off-by: Ciara Power <ciara.power@intel.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
examples/fips_validation/main.c

index 07532c9..6a1cea3 100644 (file)
@@ -1520,7 +1520,9 @@ fips_mct_aes_test(void)
                                return ret;
                        }
 
-                       get_writeback_data(&val);
+                       ret = get_writeback_data(&val);
+                       if (ret < 0)
+                               return ret;
 
                        if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
                                memcpy(prev_in, vec.ct.val, AES_BLOCK_SIZE);
@@ -1649,7 +1651,9 @@ fips_mct_sha_test(void)
                                return ret;
                        }
 
-                       get_writeback_data(&val);
+                       ret = get_writeback_data(&val);
+                       if (ret < 0)
+                               return ret;
 
                        memcpy(md[0].val, md[1].val, md[1].len);
                        md[0].len = md[1].len;