aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-03-09 15:17:02 +0100
committerGerald Combs <gerald@wireshark.org>2018-03-09 16:10:32 +0000
commita395a8b9939bd48858efbd3da5897a59d4697eba (patch)
tree350aa431f224e733f6da811ebdfb9ad25534d9ce /wsutil
parent02085c80ab10507f6a75d75fe1e43facade98a0e (diff)
GeoIP: avoid closing random file descriptors
Previously there were three different pipe validity checks: PID != WS_INVALID_PID, PID != 0 and stdin != 0. This resulted in using/closing file descriptors which might be owned by something else. When no GeoIP databases are defined, mmdb_resolve_stop would be called to close the pipe and set PID to WS_INVALID_PID. stdin is however not cleared and future invocations would try to close the previous fd. Change-Id: I1d15da29208efb41098ee6a4edeeabf61f84c2b3 Fixes: v2.5.1rc0-466-ga1da75c554 ("Transition from GeoIP Legacy to MaxMindDB.") Reviewed-on: https://code.wireshark.org/review/26391 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/ws_pipe.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/wsutil/ws_pipe.h b/wsutil/ws_pipe.h
index f0429d330d..a5f37a1040 100644
--- a/wsutil/ws_pipe.h
+++ b/wsutil/ws_pipe.h
@@ -58,6 +58,14 @@ WS_DLL_PUBLIC gboolean ws_pipe_spawn_sync ( gchar * dirname, gchar * command, gi
WS_DLL_PUBLIC void ws_pipe_init(ws_pipe_t *ws_pipe);
/**
+ * @brief Checks whether a pipe is valid (for reading or writing).
+ */
+static inline gboolean ws_pipe_valid(ws_pipe_t *ws_pipe)
+{
+ return ws_pipe && ws_pipe->pid && ws_pipe->pid != WS_INVALID_PID;
+}
+
+/**
* @brief Start a process using g_spawn_sync on UNIX and Linux, and CreateProcess on Windows.
* @param ws_pipe The process PID, stdio descriptors, etc.
* @param args The command to run along with its arguments.