Skip to content

Commit

Permalink
capture_sync: Keep PIPE_BUF_SIZE and SP_MAX_MSG_LEN related
Browse files Browse the repository at this point in the history
We might at some point want to increase SP_MAX_MSG_LEN. Make
sure that PIPE_BUF_SIZE increases in tandem, or else there can
be a segfault.
  • Loading branch information
johnthacker authored and AndersBroman committed Dec 20, 2023
1 parent c1ecdb4 commit 2b21fe5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 6 additions & 4 deletions capture/capture_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ static char *dummy_control_id;
static const char *sync_pipe_signame(int);
#endif

/* We use this pipe buffer size for both the sync message pipe and the
* data pipe. Ensure that it's large enough for the indicator and header
* plus maximum message size.
*/
#define PIPE_BUF_SIZE (SP_MAX_MSG_LEN+4)

static gboolean sync_pipe_input_cb(GIOChannel *pipe_io, capture_session *cap_session);
static int sync_pipe_wait_for_child(ws_process_id fork_child, char **msgp);
Expand Down Expand Up @@ -269,9 +274,7 @@ pipe_io_cb(GIOChannel *pipe_io, GIOCondition condition _U_, void * user_data)
* On failure, *msg points to an error message for the failure, and -1 is
* returned, in which case *msg must be freed with g_free().
*/
/* XXX - assumes PIPE_BUF_SIZE > SP_MAX_MSG_LEN */
#define ARGV_NUMBER_LEN 24
#define PIPE_BUF_SIZE 5120
static int
#ifdef _WIN32
sync_pipe_open_command(char* const argv[], int *data_read_fd,
Expand Down Expand Up @@ -960,8 +963,6 @@ sync_pipe_close_command(int *data_read_fd, GIOChannel *message_read_io,
* NULL, and -1 is returned; *primary_msg, and *secondary_msg if not NULL,
* must be freed with g_free().
*/
/* XXX - assumes PIPE_BUF_SIZE > SP_MAX_MSG_LEN */
#define PIPE_BUF_SIZE 5120
static int
sync_pipe_run_command_actual(char* const argv[], char **data, char **primary_msg,
char **secondary_msg, void(*update_cb)(void))
Expand Down Expand Up @@ -1402,6 +1403,7 @@ sync_if_list_capabilities_open(GList *if_queries,
free_argv(argv, argc);
return ret;
}

/*
* Start getting interface statistics using dumpcap. On success, read_fd
* contains the file descriptor for the pipe's stdout, *msg is unchanged,
Expand Down
7 changes: 5 additions & 2 deletions sync_pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
* message length is 3 bytes.
* XXX - this must be large enough to handle a Really Big Filter
* Expression, as the error message for an incorrect filter expression
* is a bit larger than the filter expression.
* is a bit larger than the filter expression, and large enough to
* handle a large interface list.
* 4096 is a typical PIPE_BUF size for atomic writes, but we should have
* only one writer and one reader so that shouldn't be an issue.
*/
#define SP_MAX_MSG_LEN 4096
#define SP_MAX_MSG_LEN 5116

/*
* Indications sent out on the sync pipe (from child to parent).
Expand Down

0 comments on commit 2b21fe5

Please sign in to comment.