Project

General

Profile

Bug #10224

memset_s() is not visible in global C++ namespace

Added by Alexander Pyhalov 9 months ago. Updated 9 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Start date:
2019-01-11
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage

Description

Fix for https://www.illumos.org/issues/8548 introduced std::memset_s(), but it wasn't propagated to global namespace.

So, we can have such failure:

$ /usr/gcc/6/bin/g++  -DBOOST_GEOMETRY_SQRT_CHECK_FINITENESS -DHAVE_CONFIG_H -DHAVE_LIBEVENT1 -DHAVE_OPENSSL -DHAVE_POOL_OF_THREADS -DHAVE_REPLICATION -DMYSQL_SERVER -D_FILE_OFFSET_BITS=64 -D_POSIX_PTHREAD_SEMANTICS -D_PTHREADS -D_REENTRANT -D__EXTENSIONS__ -I/export/home/alp/srcs/oi-userland/components/database/percona-server-57/build/i86/include -I/export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/extra/rapidjson/include -I/export/home/alp/srcs/oi-userland/components/database/percona-server-57/build/i86/libbinlogevents/include -I/export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/libbinlogevents/export -I/export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/include -I/export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/sql/conn_handler -I/export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/libbinlogevents/include -I/export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/sql -I/export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/sql/auth -I/export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/regex -I/export/home/alp/srcs/oi-userland/components/database/percona-server-57/build/i86/sql -I/export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/extra/lz4 -isystem /export/home/alp/srcs/oi-userland/components/database/percona-server-57/build/boost/boost_1_59_0  -m32 -O3 -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter -O3 -DNDEBUG -DDBUG_OFF -DNDEBUG -fPIC   -std=gnu++11 -o CMakeFiles/binlog.dir/binlog_crypt_data.cc.o -c /export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/sql/binlog_crypt_data.cc
/export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/sql/binlog_crypt_data.cc: In member function 'void Binlog_crypt_data::free_key(uchar*&, std::size_t&)':
/export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/sql/binlog_crypt_data.cc:62:37: error: 'memset_s' was not declared in this scope
     memset_s(key, 512, 0, key_length);
                                     ^
/export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/sql/binlog_crypt_data.cc:62:37: note: suggested alternative:
In file included from /usr/include/string.h:33:0,
                 from /export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/include/little_endian.h:22,
                 from /export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/include/my_byteorder.h:191,
                 from /export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/include/my_global.h:581,
                 from /export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/sql/binlog_crypt_data.h:20,
                 from /export/home/alp/srcs/oi-userland/components/database/percona-server-57/percona-server-5.7.22-22/sql/binlog_crypt_data.cc:17:
/usr/include/iso/string_iso.h:159:16: note:   'std::memset_s'
 extern errno_t memset_s(void *, rsize_t, int, rsize_t);

The fix is trivial:

diff --git a/usr/src/head/string.h b/usr/src/head/string.h
index 2194b70bd8..822a62d81c 100644
--- a/usr/src/head/string.h
+++ b/usr/src/head/string.h
@@ -60,6 +60,9 @@ using std::strspn;
 using std::strstr;
 using std::strtok;
 using std::strxfrm;
+#if __EXT1_VISIBLE
+using std::memset_s;
+#endif
 #endif

 #ifdef __cplusplus

History

#2

Updated by Alexander Pyhalov 9 months ago

At http://eel.is/c++draft/headers we read:

Annex K of the C standard describes a large number of functions, with associated types and macros, which “promote safer, more secure programming” than many of the traditional C library functions.
The names of the functions have a suffix of _­s; most of them provide the same service as the C library function with the unsuffixed name, but generally take an additional argument whose value is the size of the result array.
If any C++ header is included, it is implementation-defined whether any of these names is declared in the global namespace.
(None of them is declared in namespace std.)

So, the correct fix is to make memset_s() and friends visible only in global C++ namespace.

The updated fix was tested by rebuilding
percona server 5.7.22 (patched with fix for https://jira.percona.com/browse/PS-5328),
MongoDB 4.0.2
Qt 5.8.0
boost 1.64.0

Percona Server and MongoDB now find and use memset_s(), all tested software builds fine.

#3

Updated by Electric Monk 9 months ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

git commit 50971960b7b1866cdd785b20a4df98c90c231638

commit  50971960b7b1866cdd785b20a4df98c90c231638
Author: Alexander Pyhalov <apyhalov@gmail.com>
Date:   2019-01-18T02:16:47.000Z

    10224 memset_s() is not visible in global C++ namespace
    Reviewed by: Robert Mustacchi <rm@joyent.com>
    Reviewed by: Igor Kozhukhov <igor@dilos.org>
    Approved by: Dan McDonald <danmcd@joyent.com>

Also available in: Atom PDF