From 91b3c83ce71dba060f418192488debf16f003e74 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 7 Feb 2018 16:03:51 -0800 Subject: fixes #224 Windows pipe name restrictions, unicode While here, we cleaned up a few other unused variables in the HTTP code. --- src/platform/windows/win_ipc.c | 26 +++++++++++++++++++------- src/supplemental/http/http_conn.c | 2 -- src/supplemental/http/http_server.c | 4 +--- 3 files changed, 20 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/platform/windows/win_ipc.c b/src/platform/windows/win_ipc.c index 76180d23..63ba8a67 100644 --- a/src/platform/windows/win_ipc.c +++ b/src/platform/windows/win_ipc.c @@ -21,7 +21,7 @@ struct nni_plat_ipc_pipe { }; struct nni_plat_ipc_ep { - char path[256]; + WCHAR wpath[NNG_MAXADDRLEN + 16]; nni_sockaddr addr; int mode; int started; @@ -192,8 +192,13 @@ nni_plat_ipc_ep_init(nni_plat_ipc_ep **epp, const nni_sockaddr *sa, int mode) { const char * path; nni_plat_ipc_ep *ep; + char scratch[NNG_MAXADDRLEN + 16]; + int rv; path = sa->s_un.s_path.sa_path; + if (nni_strnlen(path, NNG_MAXADDRLEN) >= NNG_MAXADDRLEN) { + return (NNG_EINVAL); + } if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { return (NNG_ENOMEM); @@ -204,7 +209,14 @@ nni_plat_ipc_ep_init(nni_plat_ipc_ep **epp, const nni_sockaddr *sa, int mode) NNI_LIST_NODE_INIT(&ep->node); ep->addr = *sa; - (void) snprintf(ep->path, sizeof(ep->path), "\\\\.\\pipe\\%s", path); + (void) snprintf(scratch, sizeof(scratch), "\\\\.\\pipe\\%s", path); + rv = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, scratch, -1, + ep->wpath, NNI_NUM_ELEMENTS(ep->wpath)); + if (rv == 0) { + rv = nni_win_error(GetLastError()); + NNI_FREE_STRUCT(ep); + return (rv); + } *epp = ep; return (0); @@ -225,7 +237,7 @@ nni_plat_ipc_ep_listen(nni_plat_ipc_ep *ep) // We create the first named pipe, and we make sure that it is // properly ours. - p = CreateNamedPipeA(ep->path, + p = CreateNamedPipeW(ep->wpath, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT | @@ -274,7 +286,7 @@ nni_win_ipc_acc_finish(nni_win_event *evt, nni_aio *aio) return; } - newp = CreateNamedPipeA(ep->path, + newp = CreateNamedPipeW(ep->wpath, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS, @@ -408,9 +420,9 @@ nni_win_ipc_conn_thr(void *arg) pipe = NULL; - p = CreateFileA(ep->path, GENERIC_READ | GENERIC_WRITE, - 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, - NULL); + p = CreateFileW(ep->wpath, + GENERIC_READ | GENERIC_WRITE, 0, NULL, + OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if (p == INVALID_HANDLE_VALUE) { switch ((rv = GetLastError())) { diff --git a/src/supplemental/http/http_conn.c b/src/supplemental/http/http_conn.c index 6a72a731..726f3ea3 100644 --- a/src/supplemental/http/http_conn.c +++ b/src/supplemental/http/http_conn.c @@ -401,8 +401,6 @@ http_wr_cb(void *arg) nni_aio * uaio; int rv; size_t n; - int niov; - nni_iov * iov; nni_mtx_lock(&conn->mtx); diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c index 21a88f9e..4a426c8c 100644 --- a/src/supplemental/http/http_server.c +++ b/src/supplemental/http/http_server.c @@ -1116,8 +1116,7 @@ http_handle_file(nni_aio *aio) void * data; size_t size; int rv; - http_file * hf = nni_http_handler_get_data(h); - char * path = nni_http_handler_get_data(h); + http_file * hf = nni_http_handler_get_data(h); const char * ctype; if ((ctype = hf->ctype) == NULL) { @@ -1366,7 +1365,6 @@ nni_http_handler_init_directory( http_file * hf; nni_http_handler *h; int rv; - char * p; if ((hf = NNI_ALLOC_STRUCT(hf)) == NULL) { return (NNG_ENOMEM); -- cgit v1.2.3-70-g09d2