Fix svace defects 29/87229/1
authorKyungwook Tak <k.tak@samsung.com>
Wed, 7 Sep 2016 05:56:45 +0000 (14:56 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Wed, 7 Sep 2016 06:00:00 +0000 (15:00 +0900)
using assert() to check null is good for development
but if it is used partly (using both of assert() and if condition)
SVACE system detects it as defect because to checking it by if condition
means there is probability that it could be null.
So we should choose only one of them(To use assert() or if condition) on
entire of code.

Change-Id: I0da13027c650e11f88f5b06fa35d8f86d43ee879
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/encrypt.c
src/rsa.c

index 537fe4262ec4c3b09e98967ee96696133168350a..56b316fd8744c06b7ef59bef1d9ed6f218dc299f 100644 (file)
@@ -530,7 +530,8 @@ static int encrypt_ctx_restore(struct yaca_encrypt_context_s *c)
        }
 
        key = key_get_simple(c->backup_ctx->sym_key);
-       assert(key != NULL);
+       if (key == NULL)
+               return YACA_ERROR_INVALID_PARAMETER;
 
        ret = encrypt_ctx_init(c, c->backup_ctx->cipher, key->bit_len);
        assert(ret != YACA_ERROR_INVALID_PARAMETER);
index bf7e21a566fe871afb1c520956ead2e98bcc025d..277af343ff71d084061f68d244a513f2acc8033b 100644 (file)
--- a/src/rsa.c
+++ b/src/rsa.c
@@ -78,7 +78,8 @@ static int encrypt_decrypt(yaca_padding_e padding,
        assert(lpadding != -1);
 
        lasym_key = key_get_evp(key);
-       assert(lasym_key != NULL);
+       if (lasym_key == NULL)
+               return YACA_ERROR_INVALID_PARAMETER;
 
        ret = EVP_PKEY_size(lasym_key->evp);
        if (ret <= 0) {