[CONC-672] my_auth.c:153:5: error: 'strncpy' output may be truncated copying Created: 2023-10-17  Updated: 2023-10-26  Resolved: 2023-10-20

Status: Closed
Project: MariaDB Connector/C
Component/s: Build
Affects Version/s: 3.1, 3.3
Fix Version/s: 3.1.23, 3.3.8

Type: Bug Priority: Blocker
Reporter: Roel Van de Paar Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: compilation


 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.



 Comments   
Comment by Roel Van de Paar [ 2023-10-17 ]

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).
Comment by Sergei Golubchik [ 2023-10-19 ]

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.

Comment by Marko Mäkelä [ 2023-10-26 ]

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.

Generated at Thu Feb 08 03:07:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.