diff options
author | Tomasz Moń <desowin@gmail.com> | 2022-08-15 10:51:20 +0200 |
---|---|---|
committer | Tomasz Moń <desowin@gmail.com> | 2022-08-16 20:53:22 +0200 |
commit | c6ef99f006b64ebfe182936b263900b8119b5334 (patch) | |
tree | c7ea0828de1265445647dc128b7b161d23b71b61 /sharkd_daemon.c | |
parent | 3c3d7156282dfe8db298eba29dd67cb218965901 (diff) |
win32-utils: Explicitly list inherited handles
Windows processes inherit all inheritable handles when a new process is
created using CreateProcess() with bInheritHandles set to TRUE. This can
lead to undesired object lifetime extension. That is, the child process
will keep ineritable handles alive even if it does not use them. Up to
Windows Vista it was not possible explicitly list handles that should be
inherited. Wireshark no longer works on Windows releases earlier than
Vista, so use the new API without checking Windows version.
Require all callers to win32_create_process() to pass in the list of
handles to inherit. Set the listed handles as inheritable shortly before
calling CreateProcess() and set them as not inheritable shortly after
the process is created. This minimizes possibility for other callers
(especially in 3rd party libraries) to inherit handles by accident.
Do not terminate mmdbresolve process on exit. Instead rely on process
exit when EOF is received on standard input. Previously the EOF was
never received because mmdbresolve inherited both ends of standard input
pipe, i.e. the fact that Wireshark closed the write end was not observed
by mmdbresolve because mmdbresolve kept write handle the standard input
pipe open.
Diffstat (limited to 'sharkd_daemon.c')
-rw-r--r-- | sharkd_daemon.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/sharkd_daemon.c b/sharkd_daemon.c index e990b931ad..3b139c8b10 100644 --- a/sharkd_daemon.c +++ b/sharkd_daemon.c @@ -372,6 +372,8 @@ sharkd_loop(int argc _U_, char* argv[]) #ifndef _WIN32 pid_t pid; #else + size_t i_handles; + HANDLE handles[2]; PROCESS_INFORMATION pi; STARTUPINFO si; char *exename; @@ -415,6 +417,12 @@ sharkd_loop(int argc _U_, char* argv[]) si.hStdOutput = (HANDLE) fd; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); + i_handles = 0; + handles[i_handles++] = (HANDLE)fd; + if (si.hStdError != NULL) { + handles[i_handles++] = si.hStdError; + } + exename = ws_strdup_printf("%s\\%s", get_progfile_dir(), "sharkd.exe"); // we need to pass in all of the command line parameters except the -a parameter @@ -448,7 +456,7 @@ sharkd_loop(int argc _U_, char* argv[]) } } - if (!win32_create_process(exename, command_line, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) + if (!win32_create_process(exename, command_line, NULL, NULL, i_handles, handles, 0, NULL, NULL, &si, &pi)) { fprintf(stderr, "win32_create_process(%s) failed\n", exename); } |