From 720ad055299227b8728bcad734c4e1497f69c595 Mon Sep 17 00:00:00 2001 From: Sascha van Vliet Date: Fri, 30 Jul 2021 10:47:08 +0200 Subject: [PATCH 1/2] Fix crash in context with wide characters in path The create_ipc_wildcard_address doesn't takes wide characters into account while building a string from a temporary path. The tmpnam_s can return a path in the user temp folder which can contain special characters. The string that is returned from the create_ipc_wildcard_address will be used in the bind routine which will return an error code. --- src/ip.cpp | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/ip.cpp b/src/ip.cpp index d150da76..b9accbbe 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -868,24 +868,48 @@ void zmq::assert_success_or_recoverable (zmq::fd_t s_, int rc_) } #ifdef ZMQ_HAVE_IPC + +#if defined ZMQ_HAVE_WINDOWS +char *widechar_to_utf8 (const wchar_t *widestring) +{ + int nch, n; + char *utf8 = 0; + nch = WideCharToMultiByte (CP_UTF8, 0, widestring, -1, 0, 0, NULL, NULL); + if (nch > 0) { + utf8 = (char *)malloc ((nch + 1) * sizeof (char)); + n = WideCharToMultiByte (CP_UTF8, 0, widestring, -1, utf8, + nch, NULL, NULL); + utf8[nch] = 0; + } + return utf8; +} +#endif + int zmq::create_ipc_wildcard_address (std::string &path_, std::string &file_) { #if defined ZMQ_HAVE_WINDOWS - char buffer[MAX_PATH]; + wchar_t buffer[MAX_PATH]; { - const errno_t rc = tmpnam_s (buffer); + const errno_t rc = _wtmpnam_s (buffer); errno_assert (rc == 0); } // TODO or use CreateDirectoryA and specify permissions? - const int rc = _mkdir (buffer); + const int rc = _wmkdir (buffer); if (rc != 0) { return -1; } - path_.assign (buffer); + char* tmp = widechar_to_utf8 (buffer); + if (tmp == 0) { + return -1; + } + + path_.assign (tmp); file_ = path_ + "/socket"; + + free (tmp); #else std::string tmp_path; From efd62e3e383777069665de15bb01a22d8dd04751 Mon Sep 17 00:00:00 2001 From: Sascha van Vliet Date: Fri, 30 Jul 2021 13:28:11 +0200 Subject: [PATCH 2/2] Add missing relicense agreement To add code to the repository a relicense agreement is needed. --- RELICENSE/saschavv.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 RELICENSE/saschavv.md diff --git a/RELICENSE/saschavv.md b/RELICENSE/saschavv.md new file mode 100644 index 00000000..2328140f --- /dev/null +++ b/RELICENSE/saschavv.md @@ -0,0 +1,15 @@ +# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current ZeroMQ BDFL + +This is a statement by Sascha van Vliet +that grants permission to relicense its copyrights in the libzmq C++ +library (ZeroMQ) under the Mozilla Public License v2 (MPLv2) or any other +Open Source Initiative approved license chosen by the current ZeroMQ +BDFL (Benevolent Dictator for Life). + +A portion of the commits made by the Github handle "saschavv", with +commit author "Sascha van Vliet ", are copyright of Sascha van Vliet. +This document hereby grants the libzmq project team to relicense libzmq, +including all past, present and future contributions of the author listed above. + +Sascha van Vliet +2021/07/30