From ce6b5dba47d296b6e97482c9e734341a0897e0ac Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 31 Jan 2019 19:36:27 -0800 Subject: Have win32strerror() return a g_malloc()ated UTF-8 error message. Use FormatMessageW() to get a UTF-16-encoded Unicode error string, rather than an error string in the local code page, and then convert it from UTF-16 to UTF-8. Make it dynamically-allocated, so it's big enough and so that we are thread-safe. Make the callers free the result. Change-Id: I217aec5a644fa0176a829f181eb05561cb9d10f4 Reviewed-on: https://code.wireshark.org/review/31846 Petri-Dish: Guy Harris Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris --- capchild/capture_sync.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'capchild/capture_sync.c') diff --git a/capchild/capture_sync.c b/capchild/capture_sync.c index c3bd19cc5e..ece0ae00ad 100644 --- a/capchild/capture_sync.c +++ b/capchild/capture_sync.c @@ -206,6 +206,7 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf PROCESS_INFORMATION pi; char control_id[ARGV_NUMBER_LEN]; gchar *signal_pipe_name; + char *errmsg; #else char errmsg[1024+1]; int sync_pipe[2]; /* pipe used to send messages from child to parent */ @@ -433,8 +434,9 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf /* (increase this value if you have trouble while fast capture file switches) */ if (! CreatePipe(&sync_pipe_read, &sync_pipe_write, &sa, 5120)) { /* Couldn't create the pipe between parent and child. */ - report_failure("Couldn't create sync pipe: %s", - win32strerror(GetLastError())); + errmsg = win32strerror(GetLastError()); + report_failure("Couldn't create sync pipe: %s", errmsg); + g_free(errmsg); free_argv(argv, argc); return FALSE; } @@ -464,8 +466,9 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf if (signal_pipe == INVALID_HANDLE_VALUE) { /* Couldn't create the signal pipe between parent and child. */ - report_failure("Couldn't create signal pipe: %s", - win32strerror(GetLastError())); + errmsg = win32strerror(GetLastError()); + report_failure("Couldn't create signal pipe: %s", errmsg); + g_free(errmsg); ws_close(sync_pipe_read_fd); /* Should close sync_pipe_read */ CloseHandle(sync_pipe_write); free_argv(argv, argc); @@ -523,8 +526,10 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf /* call dumpcap */ if(!win32_create_process(argv[0], args->str, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) { + errmsg = win32strerror(GetLastError()); report_failure("Couldn't run %s in child process: %s", - args->str, win32strerror(GetLastError())); + args->str, errmsg); + g_free(errmsg); ws_close(sync_pipe_read_fd); /* Should close sync_pipe_read */ CloseHandle(sync_pipe_write); CloseHandle(signal_pipe); @@ -647,6 +652,7 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd, STARTUPINFO si; PROCESS_INFORMATION pi; int i; + char *errmsg; #else char errmsg[1024+1]; int sync_pipe[2]; /* pipe used to send messages from child to parent */ @@ -675,8 +681,9 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd, /* (increase this value if you have trouble while fast capture file switches) */ if (! CreatePipe(&sync_pipe[PIPE_READ], &sync_pipe[PIPE_WRITE], &sa, 5120)) { /* Couldn't create the message pipe between parent and child. */ - *msg = g_strdup_printf("Couldn't create sync pipe: %s", - win32strerror(GetLastError())); + errmsg = win32strerror(GetLastError()); + *msg = g_strdup_printf("Couldn't create sync pipe: %s", errmsg); + g_free(errmsg); return -1; } @@ -699,8 +706,9 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd, /* (increase this value if you have trouble while fast capture file switches) */ if (! CreatePipe(&data_pipe[PIPE_READ], &data_pipe[PIPE_WRITE], &sa, 5120)) { /* Couldn't create the message pipe between parent and child. */ - *msg = g_strdup_printf("Couldn't create data pipe: %s", - win32strerror(GetLastError())); + errmsg = win32strerror(GetLastError()); + *msg = g_strdup_printf("Couldn't create data pipe: %s", errmsg); + g_free(errmsg); ws_close(*message_read_fd); /* Should close sync_pipe[PIPE_READ] */ CloseHandle(sync_pipe[PIPE_WRITE]); return -1; @@ -752,8 +760,10 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd, /* call dumpcap */ if(!win32_create_process(argv[0], args->str, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) { + errmsg = win32strerror(GetLastError()); *msg = g_strdup_printf("Couldn't run %s in child process: %s", - args->str, win32strerror(GetLastError())); + args->str, errmsg); + g_free(errmsg); ws_close(*data_read_fd); /* Should close data_pipe[PIPE_READ] */ CloseHandle(data_pipe[PIPE_WRITE]); ws_close(*message_read_fd); /* Should close sync_pipe[PIPE_READ] */ -- cgit v1.2.3