Browse Source

Calm `scan-build` static analyser

Signed-off-by: Steffen Jaeckel <[email protected]>
Steffen Jaeckel 2 years ago
parent
commit
87665fb276

+ 8 - 8
src/encauth/ccm/ccm_test.c

@@ -215,14 +215,14 @@ int ccm_test(void)
             XMEMCPY(tag3, tests[x].tag, tests[x].taglen);
             XMEMCPY(tag3, tests[x].tag, tests[x].taglen);
             tag3[0] ^= 0xff; /* set the tag to the wrong value */
             tag3[0] ^= 0xff; /* set the tag to the wrong value */
             taglen = tests[x].taglen;
             taglen = tests[x].taglen;
-            if ((err = ccm_memory(idx,
-                                  tests[x].key, 16,
-                                  NULL,
-                                  tests[x].nonce, tests[x].noncelen,
-                                  tests[x].header, tests[x].headerlen,
-                                  buf2, tests[x].ptlen,
-                                  buf,
-                                  tag3, &taglen, 1   )) != CRYPT_ERROR) {
+            if (ccm_memory(idx,
+                           tests[x].key, 16,
+                           NULL,
+                           tests[x].nonce, tests[x].noncelen,
+                           tests[x].header, tests[x].headerlen,
+                           buf2, tests[x].ptlen,
+                           buf,
+                           tag3, &taglen, 1   ) != CRYPT_ERROR) {
                return CRYPT_FAIL_TESTVECTOR;
                return CRYPT_FAIL_TESTVECTOR;
             }
             }
             if (compare_testvector(buf2, tests[x].ptlen, zero, tests[x].ptlen, "CCM decrypt wrong tag", x)) {
             if (compare_testvector(buf2, tests[x].ptlen, zero, tests[x].ptlen, "CCM decrypt wrong tag", x)) {

+ 3 - 0
src/misc/pkcs5/pkcs_5_test.c

@@ -169,6 +169,7 @@ int pkcs_5_test (void)
                               (unsigned char*)cases_5_2[i].S, cases_5_2[i].S_len,
                               (unsigned char*)cases_5_2[i].S, cases_5_2[i].S_len,
                               cases_5_2[i].c, hash,
                               cases_5_2[i].c, hash,
                               DK, &dkLen)) != CRYPT_OK) {
                               DK, &dkLen)) != CRYPT_OK) {
+            LTC_UNUSED_PARAM(err);
 #ifdef LTC_TEST_DBG
 #ifdef LTC_TEST_DBG
             printf("\npkcs_5_alg2() #%d: Failed/1 (%s)\n", i, error_to_string(err));
             printf("\npkcs_5_alg2() #%d: Failed/1 (%s)\n", i, error_to_string(err));
 #endif
 #endif
@@ -186,6 +187,7 @@ int pkcs_5_test (void)
                               (unsigned char*)cases_5_1[i].S,
                               (unsigned char*)cases_5_1[i].S,
                               cases_5_1[i].c, hash,
                               cases_5_1[i].c, hash,
                               DK, &dkLen)) != CRYPT_OK) {
                               DK, &dkLen)) != CRYPT_OK) {
+            LTC_UNUSED_PARAM(err);
 #ifdef LTC_TEST_DBG
 #ifdef LTC_TEST_DBG
             printf("\npkcs_5_alg1() #%d: Failed/1 (%s)\n", i, error_to_string(err));
             printf("\npkcs_5_alg1() #%d: Failed/1 (%s)\n", i, error_to_string(err));
 #endif
 #endif
@@ -203,6 +205,7 @@ int pkcs_5_test (void)
                                        (unsigned char*)cases_5_1o[i].S,
                                        (unsigned char*)cases_5_1o[i].S,
                                        cases_5_1o[i].c, hash,
                                        cases_5_1o[i].c, hash,
                                        DK, &dkLen)) != CRYPT_OK) {
                                        DK, &dkLen)) != CRYPT_OK) {
+            LTC_UNUSED_PARAM(err);
 #ifdef LTC_TEST_DBG
 #ifdef LTC_TEST_DBG
             printf("\npkcs_5_alg1_openssl() #%d: Failed/1 (%s)\n", i, error_to_string(err));
             printf("\npkcs_5_alg1_openssl() #%d: Failed/1 (%s)\n", i, error_to_string(err));
 #endif
 #endif

+ 1 - 1
src/misc/ssh/ssh_encode_sequence_multi.c

@@ -134,7 +134,7 @@ int ssh_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
                   STORE32H(size, out);
                   STORE32H(size, out);
                   out += 4;
                   out += 4;
                }
                }
-               if ((err = mp_to_unsigned_bin(vdata, out)) != CRYPT_OK) {
+               if (mp_to_unsigned_bin(vdata, out) != CRYPT_OK) {
                   err = CRYPT_ERROR;
                   err = CRYPT_ERROR;
                   goto error;
                   goto error;
                }
                }

+ 2 - 2
src/pk/asn1/der/custom_type/der_encode_custom_type.c

@@ -36,7 +36,7 @@ int der_encode_custom_type(const ltc_asn1_list *root,
 
 
    /* get size of output that will be required */
    /* get size of output that will be required */
    y = 0; z = 0;
    y = 0; z = 0;
-   if ((err = der_length_custom_type(root, &y, &z)) != CRYPT_OK) return CRYPT_INVALID_ARG;
+   if (der_length_custom_type(root, &y, &z) != CRYPT_OK) return CRYPT_INVALID_ARG;
 
 
    /* too big ? */
    /* too big ? */
    if (*outlen < y) {
    if (*outlen < y) {
@@ -46,7 +46,7 @@ int der_encode_custom_type(const ltc_asn1_list *root,
    }
    }
 
 
    /* get length of the identifier, so we know the offset where to start writing */
    /* get length of the identifier, so we know the offset where to start writing */
-   if ((err = der_length_asn1_identifier(root, &id_len)) != CRYPT_OK) return CRYPT_INVALID_ARG;
+   if (der_length_asn1_identifier(root, &id_len) != CRYPT_OK) return CRYPT_INVALID_ARG;
    x = id_len;
    x = id_len;
 
 
 
 

+ 1 - 1
src/pk/asn1/der/sequence/der_encode_sequence_ex.c

@@ -33,7 +33,7 @@ int der_encode_sequence_ex(const ltc_asn1_list *list, unsigned long inlen,
 
 
    /* get size of output that will be required */
    /* get size of output that will be required */
    y = 0; z = 0;
    y = 0; z = 0;
-   if ((err = der_length_sequence_ex(list, inlen, &y, &z)) != CRYPT_OK) return CRYPT_INVALID_ARG;
+   if (der_length_sequence_ex(list, inlen, &y, &z) != CRYPT_OK) return CRYPT_INVALID_ARG;
 
 
    /* too big ? */
    /* too big ? */
    if (*outlen < y) {
    if (*outlen < y) {

+ 8 - 8
src/pk/dsa/dsa_import.c

@@ -72,14 +72,14 @@ int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key)
        }
        }
    }
    }
    /* get key type */
    /* get key type */
-   if ((err = der_decode_sequence_multi(in, inlen,
-                          LTC_ASN1_SHORT_INTEGER, 1UL, &zero,
-                          LTC_ASN1_INTEGER,      1UL, key->p,
-                          LTC_ASN1_INTEGER,      1UL, key->q,
-                          LTC_ASN1_INTEGER,      1UL, key->g,
-                          LTC_ASN1_INTEGER,      1UL, key->y,
-                          LTC_ASN1_INTEGER,      1UL, key->x,
-                          LTC_ASN1_EOL,          0UL, NULL)) == CRYPT_OK) {
+   if (der_decode_sequence_multi(in, inlen,
+                                 LTC_ASN1_SHORT_INTEGER, 1UL, &zero,
+                                 LTC_ASN1_INTEGER,       1UL, key->p,
+                                 LTC_ASN1_INTEGER,       1UL, key->q,
+                                 LTC_ASN1_INTEGER,       1UL, key->g,
+                                 LTC_ASN1_INTEGER,       1UL, key->y,
+                                 LTC_ASN1_INTEGER,       1UL, key->x,
+                                 LTC_ASN1_EOL,           0UL, NULL) == CRYPT_OK) {
 
 
        key->type = PK_PRIVATE;
        key->type = PK_PRIVATE;
    } else { /* public */
    } else { /* public */

+ 3 - 3
src/pk/ecc/ecc_import_pkcs8.c

@@ -64,7 +64,7 @@ int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen,
    if (err != CRYPT_OK) return err;
    if (err != CRYPT_OK) return err;
 
 
 
 
-   if ((err = pkcs8_decode_flexi(in, inlen, pwd, pwdlen, &l)) == CRYPT_OK) {
+   if (pkcs8_decode_flexi(in, inlen, pwd, pwdlen, &l) == CRYPT_OK) {
 
 
       /* Setup for basic structure */
       /* Setup for basic structure */
       n=0;
       n=0;
@@ -73,7 +73,7 @@ int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen,
       LTC_SET_DER_FLEXI_CHECK(flexi_should, n++, LTC_ASN1_OCTET_STRING, &priv_key);
       LTC_SET_DER_FLEXI_CHECK(flexi_should, n++, LTC_ASN1_OCTET_STRING, &priv_key);
       LTC_SET_DER_FLEXI_CHECK(flexi_should, n, LTC_ASN1_EOL, NULL);
       LTC_SET_DER_FLEXI_CHECK(flexi_should, n, LTC_ASN1_EOL, NULL);
 
 
-      if (((err = s_der_flexi_sequence_cmp(l, flexi_should)) == CRYPT_OK) &&
+      if ((s_der_flexi_sequence_cmp(l, flexi_should) == CRYPT_OK) &&
             (pk_oid_cmp_with_asn1(pka_ec_oid, seq->child) == CRYPT_OK)) {
             (pk_oid_cmp_with_asn1(pka_ec_oid, seq->child) == CRYPT_OK)) {
          ltc_asn1_list *version, *field, *point, *point_g, *order, *p_cofactor;
          ltc_asn1_list *version, *field, *point, *point_g, *order, *p_cofactor;
 
 
@@ -154,7 +154,7 @@ int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen,
 
 
          /* load private key value 'k' */
          /* load private key value 'k' */
          len = priv_key->size;
          len = priv_key->size;
-         if ((err = der_decode_sequence_flexi(priv_key->data, &len, &p)) == CRYPT_OK) {
+         if (der_decode_sequence_flexi(priv_key->data, &len, &p) == CRYPT_OK) {
             if (p->type == LTC_ASN1_SEQUENCE &&
             if (p->type == LTC_ASN1_SEQUENCE &&
                 LTC_ASN1_IS_TYPE(p->child, LTC_ASN1_INTEGER) &&
                 LTC_ASN1_IS_TYPE(p->child, LTC_ASN1_INTEGER) &&
                 LTC_ASN1_IS_TYPE(p->child->next, LTC_ASN1_OCTET_STRING)) {
                 LTC_ASN1_IS_TYPE(p->child->next, LTC_ASN1_OCTET_STRING)) {

+ 1 - 1
src/pk/rsa/rsa_verify_hash.c

@@ -136,7 +136,7 @@ int rsa_verify_hash_ex(const unsigned char *sig,            unsigned long  sigle
       LTC_SET_ASN1(siginfo,    0, LTC_ASN1_SEQUENCE,          digestinfo,                    2);
       LTC_SET_ASN1(siginfo,    0, LTC_ASN1_SEQUENCE,          digestinfo,                    2);
       LTC_SET_ASN1(siginfo,    1, LTC_ASN1_OCTET_STRING,      tmpbuf,                        siglen);
       LTC_SET_ASN1(siginfo,    1, LTC_ASN1_OCTET_STRING,      tmpbuf,                        siglen);
 
 
-      if ((err = der_decode_sequence_strict(out, outlen, siginfo, 2)) != CRYPT_OK) {
+      if (der_decode_sequence_strict(out, outlen, siginfo, 2) != CRYPT_OK) {
          /* fallback to Legacy:missing NULL */
          /* fallback to Legacy:missing NULL */
          LTC_SET_ASN1(siginfo, 0, LTC_ASN1_SEQUENCE,          digestinfo,                    1);
          LTC_SET_ASN1(siginfo, 0, LTC_ASN1_SEQUENCE,          digestinfo,                    1);
          if ((err = der_decode_sequence_strict(out, outlen, siginfo, 2)) != CRYPT_OK) {
          if ((err = der_decode_sequence_strict(out, outlen, siginfo, 2)) != CRYPT_OK) {

+ 2 - 3
tests/der_test.c

@@ -1272,19 +1272,18 @@ static void der_Xcode_run(const der_Xcode_t* x)
 {
 {
    unsigned long l1, l2, sz;
    unsigned long l1, l2, sz;
    void *d1, *d2;
    void *d1, *d2;
-   int err;
 
 
    l1 = 1;
    l1 = 1;
    d1 = XMALLOC(l1 * x->type_sz);
    d1 = XMALLOC(l1 * x->type_sz);
    sz = (x->in_sz * x->factor)/x->type_sz;
    sz = (x->in_sz * x->factor)/x->type_sz;
 
 
-   if ((err = x->encode(x->in, sz, d1, &l1)) == CRYPT_BUFFER_OVERFLOW) {
+   if (x->encode(x->in, sz, d1, &l1) == CRYPT_BUFFER_OVERFLOW) {
       d1 = XREALLOC(d1, l1 * x->type_sz);
       d1 = XREALLOC(d1, l1 * x->type_sz);
    }
    }
    DO(x->encode(x->in, sz, d1, &l1));
    DO(x->encode(x->in, sz, d1, &l1));
    l2 = 1;
    l2 = 1;
    d2 = XMALLOC(l2 * x->type_sz);
    d2 = XMALLOC(l2 * x->type_sz);
-   while ((err = x->decode(d1, l1, d2, &l2)) == CRYPT_BUFFER_OVERFLOW) {
+   while (x->decode(d1, l1, d2, &l2) == CRYPT_BUFFER_OVERFLOW) {
       d2 = XREALLOC(d2, l2 * x->type_sz);
       d2 = XREALLOC(d2, l2 * x->type_sz);
    }
    }
    DO(x->decode(d1, l1, d2, &l2));
    DO(x->decode(d1, l1, d2, &l2));

+ 2 - 2
tests/pkcs_1_test.c

@@ -14,7 +14,7 @@ int pkcs_1_test(void)
 {
 {
    unsigned char buf[3][128];
    unsigned char buf[3][128];
    int res1, res2, res3, prng_idx, hash_idx;
    int res1, res2, res3, prng_idx, hash_idx;
-   unsigned long x, y, l1, l2, l3, i1, i2, lparamlen, saltlen, modlen;
+   unsigned long x, y, l1, l2, l3, i1, lparamlen, saltlen, modlen;
    static const unsigned char lparam[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
    static const unsigned char lparam[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
 
 
    /* get hash/prng  */
    /* get hash/prng  */
@@ -75,7 +75,7 @@ int pkcs_1_test(void)
       DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res2));
       DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res2));
 
 
       buf[0][i1] ^= 1;
       buf[0][i1] ^= 1;
-      buf[1][i2 = abs(rand()) % (l1 - 1)] ^= 1;
+      buf[1][abs(rand()) % (l1 - 1)] ^= 1;
       pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res3);
       pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res3);
       if (!(res1 == 1 && res2 == 0 && res3 == 0)) {
       if (!(res1 == 1 && res2 == 0 && res3 == 0)) {
          fprintf(stderr, "PSS failed: %d, %d, %d, %lu, %lu\n", res1, res2, res3, l3, saltlen);
          fprintf(stderr, "PSS failed: %d, %d, %d, %lu, %lu\n", res1, res2, res3, l3, saltlen);