Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-672

my_auth.c:153:5: error: 'strncpy' output may be truncated copying

Details

    Description

      When building optimized ASAN builds, using GCC 11.4:

      /test/preview-11.3-preview_opt_san/libmariadb/plugins/auth/my_auth.c:153:5: error: 'strncpy' output may be truncated copying
       511 bytes from a string of length 511 [-Werror=stringop-truncation]
        153 |     strncpy(last_error, ((MCPVIO_EXT *)vio)->mysql->net.last_error,
            |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        154 |             sizeof(last_error) - 1);
            |             ~~~~~~~~~~~~~~~~~~~~~~~
      /test/preview-11.3-preview_opt_san/libmariadb/plugins/auth/my_auth.c:170:5: error: 'strncpy' output may be truncated copying
       511 bytes from a string of length 511 [-Werror=stringop-truncation]
        170 |     strncpy(mysql->net.last_error, last_error,
            |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        171 |             sizeof(mysql->net.last_error) - 1);
            |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      

      May be present in other versions too.

      Attachments

        Activity

          Roel Roel Van de Paar added a comment - - edited

          Debugging done so far:

          • The code in this area has not changed recently.
          • I could not locate any relevant references to -Werror=stringop-truncation in the code.
          • The issue does not happen when using -DCMAKE_BUILD_TYPE=Debug
          • Specifying -DCMAKE_BUILD_TYPE=RelWithDebInfo does not help.
          • With credit and thanks to serg, using cmake . -DWARNING_AS_ERROR="" prevents the issue from occurring (this sets WARNING_AS_ERROR to an empty string, and thereby disables warnings from being treated as errors).
          Roel Roel Van de Paar added a comment - - edited Debugging done so far: The code in this area has not changed recently. I could not locate any relevant references to -Werror=stringop-truncation in the code. The issue does not happen when using -DCMAKE_BUILD_TYPE=Debug Specifying -DCMAKE_BUILD_TYPE=RelWithDebInfo does not help. With credit and thanks to serg , using cmake . -DWARNING_AS_ERROR="" prevents the issue from occurring (this sets WARNING_AS_ERROR to an empty string, and thereby disables warnings from being treated as errors).
          serg Sergei Golubchik added a comment - - edited

          georg I had a similar warning/error in 3.1 with gcc 13.2.1_p20230826:

          gnutls.c

          1039
              if (p)
          1040
                strncat(prio, p, PRIO_SIZE - strlen(prio) - 1);
          1041
              token = strtok(NULL, ":");
          

          so if you want to disable stringop-truncation or -Werror, please, do it in 3.1 and merge up.

          serg Sergei Golubchik added a comment - - edited georg I had a similar warning/error in 3.1 with gcc 13.2.1_p20230826: gnutls.c 1039 if (p) 1040 strncat (prio, p, PRIO_SIZE - strlen (prio) - 1); 1041 token = strtok (NULL, ":" ); so if you want to disable stringop-truncation or -Werror , please, do it in 3.1 and merge up.

          Was the -Werror actually removed? There still are build failures on SLES 12 s390x. Check the latest 10.6, example 1 and example 2:

          10.6 2ba9702163a908d5fd195620c1d8dfc5c121b893

          /buildbot/s390x-sles-12-rpm-autobake/build/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/libmariadb/libmariadb/ma_dtoa.c: In function 'dtoa':
          /buildbot/s390x-sles-12-rpm-autobake/build/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/libmariadb/libmariadb/ma_dtoa.c:1463:14: error: this statement may fall through [-Werror=implicit-fallthrough=]
               leftright= 0;
               ~~~~~~~~~^~~
          /buildbot/s390x-sles-12-rpm-autobake/build/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/libmariadb/libmariadb/ma_dtoa.c:1465:3: note: here
             case 4:
             ^~~~
          /buildbot/s390x-sles-12-rpm-autobake/build/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/libmariadb/libmariadb/ma_dtoa.c:1471:14: error: this statement may fall through [-Werror=implicit-fallthrough=]
               leftright= 0;
               ~~~~~~~~~^~~
          /buildbot/s390x-sles-12-rpm-autobake/build/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/libmariadb/libmariadb/ma_dtoa.c:1473:3: note: here
             case 5:
             ^~~~
          cc1: all warnings being treated as errors
          libmariadb/libmariadb/CMakeFiles/mariadb_obj.dir/build.make:710: recipe for target 'libmariadb/libmariadb/CMakeFiles/mariadb_obj.dir/ma_dtoa.c.o' failed
          

          For other files, no -Werror will be set, and the bogus warnings will be ignored just fine:

          10.6 2ba9702163a908d5fd195620c1d8dfc5c121b893

          /buildbot/s390x-sles-12/build/mysys/mf_iocache.c: In function 'init_functions':
          /buildbot/s390x-sles-12/build/mysys/mf_iocache.c:99:8: warning: this statement may fall through [-Wimplicit-fallthrough=]
               if (info->myflags & MY_ENCRYPT)
                  ^
          /buildbot/s390x-sles-12/build/mysys/mf_iocache.c:106:3: note: here
             case WRITE_CACHE:
             ^~~~
          /buildbot/s390x-sles-12/build/mysys/mf_iocache.c:107:8: warning: this statement may fall through [-Wimplicit-fallthrough=]
               if (info->myflags & MY_ENCRYPT)
                  ^
          /buildbot/s390x-sles-12/build/mysys/mf_iocache.c:113:3: note: here
             case READ_FIFO:
             ^~~~
          

          I don’t think that there is any code bug to fix here; the old compiler is issuing a bogus warning because for some reason it does not recognize the /* fall through */ comments.

          marko Marko Mäkelä added a comment - Was the -Werror actually removed? There still are build failures on SLES 12 s390x. Check the latest 10.6 , example 1 and example 2 : 10.6 2ba9702163a908d5fd195620c1d8dfc5c121b893 /buildbot/s390x-sles-12-rpm-autobake/build/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/libmariadb/libmariadb/ma_dtoa.c: In function 'dtoa': /buildbot/s390x-sles-12-rpm-autobake/build/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/libmariadb/libmariadb/ma_dtoa.c:1463:14: error: this statement may fall through [-Werror=implicit-fallthrough=] leftright= 0; ~~~~~~~~~^~~ /buildbot/s390x-sles-12-rpm-autobake/build/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/libmariadb/libmariadb/ma_dtoa.c:1465:3: note: here case 4: ^~~~ /buildbot/s390x-sles-12-rpm-autobake/build/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/libmariadb/libmariadb/ma_dtoa.c:1471:14: error: this statement may fall through [-Werror=implicit-fallthrough=] leftright= 0; ~~~~~~~~~^~~ /buildbot/s390x-sles-12-rpm-autobake/build/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/libmariadb/libmariadb/ma_dtoa.c:1473:3: note: here case 5: ^~~~ cc1: all warnings being treated as errors libmariadb/libmariadb/CMakeFiles/mariadb_obj.dir/build.make:710: recipe for target 'libmariadb/libmariadb/CMakeFiles/mariadb_obj.dir/ma_dtoa.c.o' failed For other files, no -Werror will be set, and the bogus warnings will be ignored just fine: 10.6 2ba9702163a908d5fd195620c1d8dfc5c121b893 /buildbot/s390x-sles-12/build/mysys/mf_iocache.c: In function 'init_functions': /buildbot/s390x-sles-12/build/mysys/mf_iocache.c:99:8: warning: this statement may fall through [-Wimplicit-fallthrough=] if (info->myflags & MY_ENCRYPT) ^ /buildbot/s390x-sles-12/build/mysys/mf_iocache.c:106:3: note: here case WRITE_CACHE: ^~~~ /buildbot/s390x-sles-12/build/mysys/mf_iocache.c:107:8: warning: this statement may fall through [-Wimplicit-fallthrough=] if (info->myflags & MY_ENCRYPT) ^ /buildbot/s390x-sles-12/build/mysys/mf_iocache.c:113:3: note: here case READ_FIFO: ^~~~ I don’t think that there is any code bug to fix here; the old compiler is issuing a bogus warning because for some reason it does not recognize the /* fall through */ comments.

          People

            georg Georg Richter
            Roel Roel Van de Paar
            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.