Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-34348

MariaDB is violating clang-16 -Wcast-function-type-strict

Details

    Description

      D134831 introduced a compile-time check -Wcast-function-type-strict for something that had been reported by -fsanitize=undefined for a long time.

      The flag is similar to the non-strict GCC check that we have for a long time enabled by -Wextra.

      We should fix all occurrences of this warning and enable this warning in our build script when available, so that the mandatory MemorySanitizer builder that is based on clang-16 or later would fail already at compilation time.

      Attachments

        Issue Links

          Activity

            Hi marko! I've addressed your first round of review findings (PR 3490)

            bnestere Brandon Nesterenko added a comment - Hi marko ! I've addressed your first round of review findings ( PR 3490 )

            Thank you, this looks mostly good. OK to push after addressing my final comments.

            marko Marko Mäkelä added a comment - Thank you, this looks mostly good. OK to push after addressing my final comments.

            Pushed into 10.5 with head commit 773cb726a84 (and many before).

            Many merge conflicts in each forward branch. Each main branch has a dedicated *-merge-fix branch, organized with multiple incremental commits that fix relevant merge conflicts (as well as additional required fixes that are organized in the same area). In-between each version branch, the incremental commits have been squashed into the prior commit of the same domain. In other words, the incremental commits for each branch are only for that branch, and the incremental commits of the prior branches were squashed in. Branches are as follows:

            bnestere Brandon Nesterenko added a comment - Pushed into 10.5 with head commit 773cb726a84 (and many before). Many merge conflicts in each forward branch. Each main branch has a dedicated *-merge-fix branch, organized with multiple incremental commits that fix relevant merge conflicts (as well as additional required fixes that are organized in the same area). In-between each version branch, the incremental commits have been squashed into the prior commit of the same domain. In other words, the incremental commits for each branch are only for that branch, and the incremental commits of the prior branches were squashed in. Branches are as follows: bb-10.6-MDEV-34348-merge-fix bb-10.11-MDEV-34348-merge-fix bb-11.4-MDEV-34348-merge-fix 11.7 is to-come (still needs one last minor decision to be made before push)

            Note: In the PARSEC authentication plugin in MariaDB Connector/C version 3.4 (CONC-743) we are unable to fix this warning. I just mentioned the problem to the author of Nettle today, and he is reluctant to fix that. So, we may need to suppress -fsanitize=undefined in the function compute_derived_key() when not using this implementation:

            int compute_derived_key(const char* password, size_t pass_len,
                                    const struct Passwd_in_memory *params,
                                    uchar *derived_key)
            {
            #if defined(HAVE_OPENSSL)
              return !PKCS5_PBKDF2_HMAC(password, (int)pass_len, params->salt,
                                        CHALLENGE_SALT_LENGTH,
                                        1 << (params->iterations + 10),
                                        EVP_sha512(), PBKDF2_HASH_LENGTH, derived_key);
            #elif defined(HAVE_GNUTLS) /* HAVE_GNUTLS */
              struct hmac_sha512_ctx ctx;
              hmac_sha512_set_key(&ctx, pass_len, (const uint8_t *)password);
             
              /*
                pbkdf2/nettle functions are third party, so ignore the bad function casts
              */
            # if defined __clang_major__ && __clang_major__ >= 16
            #  pragma clang diagnostic push
            #  pragma clang diagnostic ignored "-Wcast-function-type-strict"
            # endif
              pbkdf2(&ctx, (nettle_hash_update_func *)hmac_sha512_update,
                     (nettle_hash_digest_func *)hmac_sha512_digest, SHA512_DIGEST_SIZE,
                     1024 << params->iterations, CHALLENGE_SALT_LENGTH, params->salt,
                     PBKDF2_HASH_LENGTH, derived_key);
            # ifdef __clang__
            #  pragma clang diagnostic pop
            # endif
            

            Actually, I realize that we could write our own wrapper functions when we’re running under clang. For other compilers that we are aware of (GCC, MSVC), the function pointer cast seems to work fine.

            marko Marko Mäkelä added a comment - Note: In the PARSEC authentication plugin in MariaDB Connector/C version 3.4 ( CONC-743 ) we are unable to fix this warning. I just mentioned the problem to the author of Nettle today, and he is reluctant to fix that. So, we may need to suppress -fsanitize=undefined in the function compute_derived_key() when not using this implementation: int compute_derived_key( const char * password, size_t pass_len, const struct Passwd_in_memory *params, uchar *derived_key) { #if defined(HAVE_OPENSSL) return !PKCS5_PBKDF2_HMAC(password, ( int )pass_len, params->salt, CHALLENGE_SALT_LENGTH, 1 << (params->iterations + 10), EVP_sha512(), PBKDF2_HASH_LENGTH, derived_key); #elif defined(HAVE_GNUTLS) /* HAVE_GNUTLS */ struct hmac_sha512_ctx ctx; hmac_sha512_set_key(&ctx, pass_len, ( const uint8_t *)password);   /* pbkdf2/nettle functions are third party, so ignore the bad function casts */ # if defined __clang_major__ && __clang_major__ >= 16 # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wcast-function-type-strict" # endif pbkdf2(&ctx, (nettle_hash_update_func *)hmac_sha512_update, (nettle_hash_digest_func *)hmac_sha512_digest, SHA512_DIGEST_SIZE, 1024 << params->iterations, CHALLENGE_SALT_LENGTH, params->salt, PBKDF2_HASH_LENGTH, derived_key); # ifdef __clang__ # pragma clang diagnostic pop # endif Actually, I realize that we could write our own wrapper functions when we’re running under clang. For other compilers that we are aware of (GCC, MSVC), the function pointer cast seems to work fine.
            danblack Daniel Black added a comment - C/C makecontext masking - https://github.com/mariadb-corporation/mariadb-connector-c/pull/274

            People

              bnestere Brandon Nesterenko
              marko Marko Mäkelä
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.