nixpkgs/pkgs/applications/networking/sniffers/wireshark/wireshark-lookup-dumpcap-in-path.patch
Daniel Albert 735ab1984b
wireshark: 3.6.5 -> 4.0.1
The release notes for the major update to 4.0.0 are at
https://www.wireshark.org/news/20221004.html

The release notes for the 4.0.1 release can be found at
https://www.wireshark.org/docs/relnotes/wireshark-4.0.1.html
2022-11-05 14:47:10 +01:00

67 lines
2.6 KiB
Diff

From 2f0cbc740a0fe050f4de082620296c5eea18eba3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= <bjorn.forsman@gmail.com>
Date: Thu, 27 Oct 2022 20:56:07 +0200
Subject: [PATCH] Lookup dumpcap in PATH
NixOS patch: Look for dumpcap in PATH first, because there may be a
dumpcap wrapper that we want to use instead of the default
non-setuid dumpcap binary.
Also change execv() to execvp() because we've set argv[0] to "dumpcap"
and have to enable PATH lookup. Wireshark is not a setuid program, so
looking in PATH is not a security issue.
ORIGINALLY by Björn Forsman
EDITED by teto for wireshark 3.6
EDITED by esclear for wireshark 4.0
Signed-off-by: Franz Pletz <fpletz@fnordicwalking.de>
---
capture/capture_sync.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/capture/capture_sync.c b/capture/capture_sync.c
index fc5552f02c..a556f109af 100644
--- a/capture/capture_sync.c
+++ b/capture/capture_sync.c
@@ -239,7 +239,18 @@ init_pipe_args(int *argc) {
#ifdef _WIN32
exename = ws_strdup_printf("%s\\dumpcap.exe", progfile_dir);
#else
- exename = ws_strdup_printf("%s/dumpcap", progfile_dir);
+ /*
+ * NixOS patch: Look for dumpcap in PATH first, because there may be a
+ * dumpcap wrapper that we want to use instead of the default
+ * non-setuid dumpcap binary.
+ */
+ if (system("command -v dumpcap >/dev/null") == 0) {
+ /* Found working dumpcap */
+ exename = ws_strdup_printf("dumpcap");
+ } else {
+ /* take Wireshark's absolute program path and replace "Wireshark" with "dumpcap" */
+ exename = ws_strdup_printf("%s/dumpcap", progfile_dir);
+ }
#endif
/* Make that the first argument in the argument list (argv[0]). */
@@ -690,7 +701,7 @@ sync_pipe_start(capture_options *capture_opts, GPtrArray *capture_comments,
*/
dup2(sync_pipe[PIPE_WRITE], 2);
ws_close(sync_pipe[PIPE_READ]);
- execv(argv[0], argv);
+ execvp(argv[0], argv);
snprintf(errmsg, sizeof errmsg, "Couldn't run %s in child process: %s",
argv[0], g_strerror(errno));
sync_pipe_errmsg_to_parent(2, errmsg, "");
@@ -946,7 +957,7 @@ sync_pipe_open_command(char* const argv[], int *data_read_fd,
dup2(sync_pipe[PIPE_WRITE], 2);
ws_close(sync_pipe[PIPE_READ]);
ws_close(sync_pipe[PIPE_WRITE]);
- execv(argv[0], argv);
+ execvp(argv[0], argv);
snprintf(errmsg, sizeof errmsg, "Couldn't run %s in child process: %s",
argv[0], g_strerror(errno));
sync_pipe_errmsg_to_parent(2, errmsg, "");