mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 10:52:56 +01:00
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.
This commit is contained in:
parent
a2d21f63cf
commit
720ad05529
32
src/ip.cpp
32
src/ip.cpp
@ -868,24 +868,48 @@ void zmq::assert_success_or_recoverable (zmq::fd_t s_, int rc_)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ZMQ_HAVE_IPC
|
#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_)
|
int zmq::create_ipc_wildcard_address (std::string &path_, std::string &file_)
|
||||||
{
|
{
|
||||||
#if defined ZMQ_HAVE_WINDOWS
|
#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);
|
errno_assert (rc == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO or use CreateDirectoryA and specify permissions?
|
// TODO or use CreateDirectoryA and specify permissions?
|
||||||
const int rc = _mkdir (buffer);
|
const int rc = _wmkdir (buffer);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
path_.assign (buffer);
|
char* tmp = widechar_to_utf8 (buffer);
|
||||||
|
if (tmp == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
path_.assign (tmp);
|
||||||
file_ = path_ + "/socket";
|
file_ = path_ + "/socket";
|
||||||
|
|
||||||
|
free (tmp);
|
||||||
#else
|
#else
|
||||||
std::string tmp_path;
|
std::string tmp_path;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user