Bug #97466 gcc 9.2.1 reports a new warning for os_file_get_parent_dir
Submitted: 4 Nov 2019 10:36 Modified: 19 Nov 2019 18:56
Reporter: Przemysław Skibiński (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.7.28, 8.0.18 OS:Any
Assigned to: CPU Architecture:Any

[4 Nov 2019 10:36] Przemysław Skibiński
Description:
The newest gcc 9.2.1 from Ubuntu Bionic reports:

In file included from /usr/include/string.h:494,
                 from /data/mysql-server/mysql-8.0/include/my_dbug.h:37,
                 from /data/mysql-server/mysql-8.0/storage/innobase/include/os0file.h:44,
                 from /data/mysql-server/mysql-8.0/storage/innobase/os/os0file.cc:41:
In function ‘void* memcpy(void*, const void*, size_t)’,
    inlined from ‘char* mem_strdupl(const char*, ulint)’ at /data/mysql-server/mysql-8.0/storage/innobase/include/mem0mem.ic:555:11,
    inlined from ‘char* os_file_get_parent_dir(const char*)’ at /data/mysql-server/mysql-8.0/storage/innobase/os/os0file.cc:1794:22,
    inlined from ‘dberr_t os_file_create_subdirs_if_needed(const char*)’ at /data/mysql-server/mysql-8.0/storage/innobase/os/os0file.cc:1863:40:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:34:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
   34 |   return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors

How to repeat:
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DMYSQL_MAINTAINER_MODE=ON -DBUILD_CONFIG=mysql_release -DFEATURE_SET=community

Suggested fix:
diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc
index 7172ddc51aa..53dd69ab8be 100644
--- a/storage/innobase/os/os0file.cc
+++ b/storage/innobase/os/os0file.cc
@@ -1789,6 +1789,10 @@ static char *os_file_get_parent_dir(const char *path) {
     return (NULL);
   }
 
+  if (last_slash - path < 0) {
+    return (NULL);
+  }
+
   /* Non-trivial directory component */
 
   return (mem_strdupl(path, last_slash - path));
[4 Nov 2019 12:07] MySQL Verification Team
Hello Przemysław,

Thank you for the report and feedback.
Verified as described on OL7(MySQL server 8.0.18, gcc 9.2.0 built using source).

Thanks,
Umesh
[19 Nov 2019 18:56] Daniel Price
Posted by developer:
 
Fixed as of the upcoming 5.7.29, 8.0.19 release, and here's the changelog entry:

 os_file_get_parent_dir warnings were encountered when compiling MySQL
with GCC 9.2.0.