]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
devel: suppress cppcheck 2.5 false-positives
authorDaiki Ueno <ueno@gnu.org>
Tue, 3 Aug 2021 09:44:52 +0000 (11:44 +0200)
committerDaiki Ueno <ueno@gnu.org>
Wed, 4 Aug 2021 04:45:25 +0000 (06:45 +0200)
This fixes errors and warnings as well as some style issues spotted by
cppcheck 2.5.  Others are recorded in the suppressions file.

Signed-off-by: Daiki Ueno <ueno@gnu.org>
12 files changed:
devel/cppcheck.suppressions
lib/ext/safe_renegotiation.c
lib/session.c
lib/state.c
lib/x509/attributes.c
lib/x509/crl.c
lib/x509/dn.c
lib/x509/extensions.c
lib/x509/ocsp_output.c
lib/x509/pkcs12.c
lib/x509/pkcs7.c
lib/x509/x509.c

index 2273647a4f7ef11ad9cc4718a1aafb34e82ca94c..c572747c3022fbc26a3da1b2698551925072d5b5 100644 (file)
@@ -1,6 +1,19 @@
 allocaCalled:lib/nettle/int/pss*.c
+allocaCalled:lib/accelerated/afalg.c
 variableScope:lib/safe-memfuncs.c:42
 variableScope:gl/gettext.h
 redundantAssignment:lib/nettle/backport/cmac.c:132
 variableScope:lib/inih/ini.c:97
 variableScope:lib/inih/ini.c:241
+uninitvar:lib/accelerated/aarch64/sha-aarch64.c:207
+uninitvar:lib/accelerated/x86/sha-x86-ssse3.c:207
+objectIndex:lib/num.h:59
+objectIndex:lib/num.h:60
+objectIndex:lib/str_array.h:75
+invalidLifetime:lib/pkcs11_privkey.c:602
+invalidLifetime:lib/pkcs11_privkey.c:603
+invalidLifetime:lib/pkcs11_privkey.c:604
+invalidLifetime:lib/pkcs11_privkey.c:606
+autoVariables:lib/stek.c:302
+autoVariables:lib/stek.c:306
+autoVariables:lib/stek.c:310
index 0b3d797bbd2b1a43f4a3279575f24590d850c7bb..f76895d618481ce22586780ccd13e0d171a135c0 100644 (file)
@@ -254,12 +254,11 @@ int _gnutls_ext_sr_send_cs(gnutls_session_t session)
                        return GNUTLS_E_MEMORY_ERROR;
                }
                epriv = priv;
-       }
 
-       if (set != 0)
                _gnutls_hello_ext_set_priv(session,
                                             GNUTLS_EXTENSION_SAFE_RENEGOTIATION,
                                             epriv);
+       }
 
        return 0;
 }
index bdaf572b0ead6b08eb52c89c88175c3bda7e84cd..744c83d0c63484324be16ae02f09aee5fb6cda6e 100644 (file)
@@ -385,7 +385,7 @@ char *gnutls_session_get_desc(gnutls_session_t session)
        if (group_name == NULL && _gnutls_kx_is_dhe(kx)) {
                dh_bits = gnutls_dh_get_prime_bits(session);
                if (dh_bits > 0)
-                       snprintf(_group_name, sizeof(_group_name), "CUSTOM%u", dh_bits);
+                       snprintf(_group_name, sizeof(_group_name), "CUSTOM%d", dh_bits);
                else
                        snprintf(_group_name, sizeof(_group_name), "CUSTOM");
                group_name = _group_name;
index f42c6ae6db47e41b1ea6e5a7a6ebf2935f82fc42..bd55a4be57553abfdd1ccd6708cf1d5698905a78 100644 (file)
@@ -1386,8 +1386,7 @@ gnutls_session_channel_binding(gnutls_session_t session,
                        gnutls_x509_crt_deinit (cert);
                        return GNUTLS_E_UNIMPLEMENTED_FEATURE;
                default:
-                       /* no-op */
-                       algo = algo;
+                       break;
                }
 
                /* preallocate 512 bits buffer as maximum supported digest */
index 12b77a96d9a6125657310e29087073ddef0c2fa3..3aab65b360c1282b0e21d11173dc34b74b7dbfbd 100644 (file)
@@ -89,10 +89,10 @@ _x509_parse_attribute(asn1_node asn1_struct,
                /* create a string like "attribute.?1"
                 */
                if (attr_name[0] != 0)
-                       snprintf(tmpbuffer1, sizeof(tmpbuffer1), "%s.?%u",
+                       snprintf(tmpbuffer1, sizeof(tmpbuffer1), "%s.?%d",
                                 attr_name, k1);
                else
-                       snprintf(tmpbuffer1, sizeof(tmpbuffer1), "?%u",
+                       snprintf(tmpbuffer1, sizeof(tmpbuffer1), "?%d",
                                 k1);
 
                len = sizeof(value) - 1;
@@ -244,7 +244,7 @@ _x509_set_attribute(asn1_node asn, const char *root,
        do {
                k++;
 
-               snprintf(name, sizeof(name), "%s.?%u", root, k);
+               snprintf(name, sizeof(name), "%s.?%d", root, k);
 
                len = sizeof(extnID) - 1;
                result = asn1_read_value(asn, name, extnID, &len);
index d9e7ce0722b45648fb781db90423960b79dd56ae..56103e105b613f9eea8607f6c76e8ab164b05d9e 100644 (file)
@@ -684,7 +684,7 @@ gnutls_x509_crl_iter_crt_serial(gnutls_x509_crl_t crl,
                (*iter)->rcache_idx = 1;
        } else {
                snprintf(serial_name, sizeof(serial_name),
-                        "?%d", (*iter)->rcache_idx);
+                        "?%u", (*iter)->rcache_idx);
                (*iter)->rcache = asn1_find_node ((*iter)->rcache, serial_name);
        }
        if ((*iter)->rcache == NULL) {
@@ -694,7 +694,7 @@ gnutls_x509_crl_iter_crt_serial(gnutls_x509_crl_t crl,
        }
 
        snprintf(serial_name, sizeof(serial_name),
-                "?%d.userCertificate", (*iter)->rcache_idx);
+                "?%u.userCertificate", (*iter)->rcache_idx);
 
        _serial_size = *serial_size;
        result =
@@ -713,7 +713,7 @@ gnutls_x509_crl_iter_crt_serial(gnutls_x509_crl_t crl,
 
        if (t) {
                snprintf(date_name, sizeof(date_name),
-                        "?%d.revocationDate", (*iter)->rcache_idx);
+                        "?%u.revocationDate", (*iter)->rcache_idx);
                *t = _gnutls_x509_get_time((*iter)->rcache, date_name, 0);
        }
 
index c13119edfa7fdc3dc32bf8ad3bd5c635c6626aaa..0a703a84641013d4e12220faf8124320bd200734 100644 (file)
@@ -49,10 +49,10 @@ static int append_elements(asn1_node asn1_struct, const char *asn1_rdn_name, gnu
        /* create a string like "tbsCertList.issuer.rdnSequence.?1"
         */
        if (asn1_rdn_name[0] != 0)
-               snprintf(tmpbuffer1, sizeof(tmpbuffer1), "%s.?%u",
+               snprintf(tmpbuffer1, sizeof(tmpbuffer1), "%s.?%d",
                         asn1_rdn_name, k1);
        else
-               snprintf(tmpbuffer1, sizeof(tmpbuffer1), "?%u",
+               snprintf(tmpbuffer1, sizeof(tmpbuffer1), "?%d",
                         k1);
 
        len = sizeof(value) - 1;
@@ -80,10 +80,10 @@ static int append_elements(asn1_node asn1_struct, const char *asn1_rdn_name, gnu
 
                if (tmpbuffer1[0] != 0)
                        snprintf(tmpbuffer2, sizeof(tmpbuffer2),
-                                "%s.?%u", tmpbuffer1, k2);
+                                "%s.?%d", tmpbuffer1, k2);
                else
                        snprintf(tmpbuffer2, sizeof(tmpbuffer2),
-                                "?%u", k2);
+                                "?%d", k2);
 
                /* Try to read the RelativeDistinguishedName attributes.
                 */
@@ -336,10 +336,10 @@ _gnutls_x509_parse_dn_oid(asn1_node asn1_struct,
                /* create a string like "tbsCertList.issuer.rdnSequence.?1"
                 */
                if (asn1_rdn_name[0] != 0)
-                       snprintf(tmpbuffer1, sizeof(tmpbuffer1), "%s.?%u",
+                       snprintf(tmpbuffer1, sizeof(tmpbuffer1), "%s.?%d",
                                 asn1_rdn_name, k1);
                else
-                       snprintf(tmpbuffer1, sizeof(tmpbuffer1), "?%u",
+                       snprintf(tmpbuffer1, sizeof(tmpbuffer1), "?%d",
                                 k1);
 
                len = sizeof(value) - 1;
@@ -365,10 +365,10 @@ _gnutls_x509_parse_dn_oid(asn1_node asn1_struct,
 
                        if (tmpbuffer1[0] != 0)
                                snprintf(tmpbuffer2, sizeof(tmpbuffer2),
-                                        "%s.?%u", tmpbuffer1, k2);
+                                        "%s.?%d", tmpbuffer1, k2);
                        else
                                snprintf(tmpbuffer2, sizeof(tmpbuffer2),
-                                        "?%u", k2);
+                                        "?%d", k2);
 
                        /* Try to read the RelativeDistinguishedName attributes.
                         */
@@ -496,10 +496,10 @@ _gnutls_x509_get_dn_oid(asn1_node asn1_struct,
                /* create a string like "tbsCertList.issuer.rdnSequence.?1"
                 */
                if (asn1_rdn_name[0] != 0)
-                       snprintf(tmpbuffer1, sizeof(tmpbuffer1), "%s.?%u",
+                       snprintf(tmpbuffer1, sizeof(tmpbuffer1), "%s.?%d",
                                 asn1_rdn_name, k1);
                else
-                       snprintf(tmpbuffer1, sizeof(tmpbuffer1), "?%u",
+                       snprintf(tmpbuffer1, sizeof(tmpbuffer1), "?%d",
                                 k1);
 
                len = sizeof(value) - 1;
@@ -525,10 +525,10 @@ _gnutls_x509_get_dn_oid(asn1_node asn1_struct,
 
                        if (tmpbuffer1[0] != 0)
                                snprintf(tmpbuffer2, sizeof(tmpbuffer2),
-                                        "%s.?%u", tmpbuffer1, k2);
+                                        "%s.?%d", tmpbuffer1, k2);
                        else
                                snprintf(tmpbuffer2, sizeof(tmpbuffer2),
-                                        "?%u", k2);
+                                        "?%d", k2);
 
                        /* Try to read the RelativeDistinguishedName attributes.
                         */
index 9e5b72bbd3f2a6c5a58dae276c5ebbbb4c93ef86..dc333f4d3dac6272750ce86e9d424c5dd18b3382 100644 (file)
@@ -53,7 +53,7 @@ _gnutls_get_extension(asn1_node asn, const char *root,
        do {
                k++;
 
-               snprintf(name, sizeof(name), "%s.?%u", root, k);
+               snprintf(name, sizeof(name), "%s.?%d", root, k);
 
                _gnutls_str_cpy(name2, sizeof(name2), name);
                _gnutls_str_cat(name2, sizeof(name2), ".extnID");
@@ -140,7 +140,7 @@ get_indx_extension(asn1_node asn, const char *root,
        out->data = NULL;
        out->size = 0;
 
-       snprintf(name, sizeof(name), "%s.?%u.extnValue", root, indx+1);
+       snprintf(name, sizeof(name), "%s.?%d.extnValue", root, indx+1);
 
        ret = _gnutls_x509_read_value(asn, name, out);
        if (ret < 0)
@@ -238,7 +238,7 @@ static int get_extension_oid(asn1_node asn, const char *root,
        do {
                k++;
 
-               snprintf(name, sizeof(name), "%s.?%u", root, k);
+               snprintf(name, sizeof(name), "%s.?%d", root, k);
 
                _gnutls_str_cpy(name2, sizeof(name2), name);
                _gnutls_str_cat(name2, sizeof(name2), ".extnID");
@@ -430,9 +430,9 @@ _gnutls_set_extension(asn1_node asn, const char *root,
                k++;
 
                if (root[0] != 0)
-                       snprintf(name, sizeof(name), "%s.?%u", root, k);
+                       snprintf(name, sizeof(name), "%s.?%d", root, k);
                else
-                       snprintf(name, sizeof(name), "?%u", k);
+                       snprintf(name, sizeof(name), "?%d", k);
 
                len = sizeof(extnID) - 1;
                result = asn1_read_value(asn, name, extnID, &len);
index 4e7219767e899da2dff1a15a8a2fa86d86cc2718..8ead90c4661762cefbbaf61290370c7ec34bb466 100644 (file)
@@ -530,11 +530,13 @@ print_resp(gnutls_buffer_st * str, gnutls_ocsp_resp_const_t resp,
                       "algorithm that can be forged.\n"));
        }
 
-       /* Signature. */
        if (format == GNUTLS_OCSP_PRINT_FULL) {
                gnutls_datum_t sig;
+               gnutls_x509_crt_t *certs;
+               size_t ncerts, i;
+               gnutls_datum_t out;
 
-
+               /* Signature. */
                ret = gnutls_ocsp_resp_get_signature(resp, &sig);
                if (ret < 0)
                        addf(str, "error: get_signature: %s\n",
@@ -546,14 +548,8 @@ print_resp(gnutls_buffer_st * str, gnutls_ocsp_resp_const_t resp,
 
                        gnutls_free(sig.data);
                }
-       }
-
-       /* certs */
-       if (format == GNUTLS_OCSP_PRINT_FULL) {
-               gnutls_x509_crt_t *certs;
-               size_t ncerts, i;
-               gnutls_datum_t out;
 
+               /* certs */
                ret = gnutls_ocsp_resp_get_certs(resp, &certs, &ncerts);
                if (ret < 0)
                        addf(str, "error: get_certs: %s\n",
index 8ab58d673b54cfeeac682170af6c72bc6a51ede6..504d3c31a8ccf068bf23f0ea846e07247bc3e880 100644 (file)
@@ -475,7 +475,7 @@ _pkcs12_decode_safe_contents(const gnutls_datum_t * content,
                        for (j = 0; j < attributes; j++) {
 
                                snprintf(root, sizeof(root),
-                                        "?%u.bagAttributes.?%u", i + 1,
+                                        "?%u.bagAttributes.?%d", i + 1,
                                         j + 1);
 
                                result =
@@ -621,7 +621,7 @@ gnutls_pkcs12_get_bag(gnutls_pkcs12_t pkcs12,
        /* Step 2. Parse the AuthenticatedSafe
         */
 
-       snprintf(root2, sizeof(root2), "?%u.contentType", indx + 1);
+       snprintf(root2, sizeof(root2), "?%d.contentType", indx + 1);
 
        len = sizeof(oid) - 1;
        result = asn1_read_value(c2, root2, oid, &len);
@@ -640,7 +640,7 @@ gnutls_pkcs12_get_bag(gnutls_pkcs12_t pkcs12,
        /* Not encrypted Bag
         */
 
-       snprintf(root2, sizeof(root2), "?%u.content", indx + 1);
+       snprintf(root2, sizeof(root2), "?%d.content", indx + 1);
 
        if (strcmp(oid, DATA_OID) == 0) {
                result = _parse_safe_contents(c2, root2, bag);
index e930b4dd71ac064c63ab1ae742520fdf21f0ca8a..1f35fab8719464cfeb2c428150608a38060c4a23 100644 (file)
@@ -1769,7 +1769,7 @@ int gnutls_pkcs7_delete_crt(gnutls_pkcs7_t pkcs7, int indx)
        /* Step 2. Delete the certificate.
         */
 
-       snprintf(root2, sizeof(root2), "certificates.?%u", indx + 1);
+       snprintf(root2, sizeof(root2), "certificates.?%d", indx + 1);
 
        result = asn1_write_value(pkcs7->signed_data, root2, NULL, 0);
        if (result != ASN1_SUCCESS) {
@@ -2033,7 +2033,7 @@ int gnutls_pkcs7_delete_crl(gnutls_pkcs7_t pkcs7, int indx)
        /* Delete the crl.
         */
 
-       snprintf(root2, sizeof(root2), "crls.?%u", indx + 1);
+       snprintf(root2, sizeof(root2), "crls.?%d", indx + 1);
 
        result = asn1_write_value(pkcs7->signed_data, root2, NULL, 0);
        if (result != ASN1_SUCCESS) {
index 257a22369995105379ce1b178f793c690d6bb31c..4c5085e7a0dcee5675d8c634ebdff16664d8b48f 100644 (file)
@@ -1687,9 +1687,9 @@ _gnutls_parse_general_name2(asn1_node src, const char *src_name,
                seq++;  /* 0->1, 1->2 etc */
 
                if (src_name[0] != 0)
-                       snprintf(nptr, sizeof(nptr), "%s.?%u", src_name, seq);
+                       snprintf(nptr, sizeof(nptr), "%s.?%d", src_name, seq);
                else
-                       snprintf(nptr, sizeof(nptr), "?%u", seq);
+                       snprintf(nptr, sizeof(nptr), "?%d", seq);
        } else {
                snprintf(nptr, sizeof(nptr), "%s", src_name);
        }
@@ -1737,11 +1737,11 @@ _gnutls_parse_general_name2(asn1_node src, const char *src_name,
 
                        if (src_name[0] != 0)
                                snprintf(nptr, sizeof(nptr),
-                                        "%s.?%u.otherName.type-id",
+                                        "%s.?%d.otherName.type-id",
                                         src_name, seq);
                        else
                                snprintf(nptr, sizeof(nptr),
-                                        "?%u.otherName.type-id", seq);
+                                        "?%d.otherName.type-id", seq);
 
                        len = sizeof(oid);