Fix for SVACE DEREF_AFTER_NULL 52/157052/3
authorJaroslaw Pelczar <j.pelczar@samsung.com>
Fri, 20 Oct 2017 15:53:47 +0000 (17:53 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Tue, 24 Oct 2017 08:49:12 +0000 (10:49 +0200)
DEREF_AFTER_NULL: After having been compared to NULL value at
ssf_crypto.cpp:1990, pointer 'key1' is dereferenced at
ssf_crypto.cpp:1999.
    [dereference] Dereference at /home/abuild/rpmbuild/BUILD/tef-
simulator-0.0.1/ssflib/src/ssf_crypto.cpp:1999
    [null check] null check at /home/abuild/rpmbuild/BUILD/tef-
simulator-0.0.1/ssflib/src/ssf_crypto.cpp:1990

Change-Id: Iaf1ed9dd32b30bc958a91ac1a30382c71b3d4b43
Signed-off-by: Jaroslaw Pelczar <j.pelczar@samsung.com>
ssflib/src/ssf_crypto.cpp

index 96f9489..4780887 100644 (file)
@@ -1996,15 +1996,20 @@ TEE_Result TEE_SetOperationKey2( TEE_OperationHandle operation, TEE_ObjectHandle
                return TEE_SUCCESS;
        }
 
-       if ((key1->tr.info.objectUsage | ~op->info.requiredKeyUsage) != 0xffffffff) {
+       if (key1 && (key1->tr.info.objectUsage | ~op->info.requiredKeyUsage) != 0xffffffff) {
                CRYPTO_PANIC;
        }
-       if ((key2->tr.info.objectUsage | ~op->info.requiredKeyUsage) != 0xffffffff) {
+       if (key2 && (key2->tr.info.objectUsage | ~op->info.requiredKeyUsage) != 0xffffffff) {
                CRYPTO_PANIC;
        }
 
-       TEE_CopyObjectAttributes(op->key1, key1);
-       TEE_CopyObjectAttributes(op->key2, key2);
+       if(key1) {
+               TEE_CopyObjectAttributes(op->key1, key1);
+       }
+
+       if(key2) {
+               TEE_CopyObjectAttributes(op->key2, key2);
+       }
 
        op->info.handleState |= TEE_HANDLE_FLAG_KEY_SET;
        return TEE_SUCCESS;