From: Tzvetomir Stoyanov <tstoyanov@xxxxxxxxxx> By definition, communication ports used by trace-cmd clients are 32 bit unsigned integers. These ports are generated randomly, and in some implementations can overlap the signed integer range. This patch converts all client ports in trace-cmd to be unsigned 32 bit integers. Signed-off-by: Tzvetomir Stoyanov <tstoyanov@xxxxxxxxxx> Signed-off-by: Slavomir Kaslev <kaslevs@xxxxxxxxxx> --- include/trace-cmd/trace-cmd.h | 2 +- tracecmd/trace-msg.c | 4 ++-- tracecmd/trace-record.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index ff4f0f7..8b43462 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -322,7 +322,7 @@ void tracecmd_msg_handle_close(struct tracecmd_msg_handle *msg_handle); /* for clients */ int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle, - int **client_ports); + unsigned int **client_ports); int tracecmd_msg_data_send(struct tracecmd_msg_handle *msg_handle, const char *buf, int size); int tracecmd_msg_finish_sending_data(struct tracecmd_msg_handle *msg_handle); diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c index edde582..529ae2a 100644 --- a/tracecmd/trace-msg.c +++ b/tracecmd/trace-msg.c @@ -386,12 +386,12 @@ static int tracecmd_msg_wait_for_msg(int fd, struct tracecmd_msg *msg) } int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle, - int **client_ports) + unsigned int **client_ports) { struct tracecmd_msg send_msg; struct tracecmd_msg recv_msg; int fd = msg_handle->fd; - int *ports; + unsigned int *ports; int i, cpus; int ret; diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index a8c3464..3034a4b 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -74,7 +74,7 @@ static int buffers; static int clear_function_filters; static char *host; -static int *client_ports; +static unsigned int *client_ports; static int sfd; /* Max size to let a per cpu file get */ @@ -2545,7 +2545,7 @@ static void connect_port(int cpu) int s; char buf[BUFSIZ]; - snprintf(buf, BUFSIZ, "%d", client_ports[cpu]); + snprintf(buf, BUFSIZ, "%u", client_ports[cpu]); memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; @@ -2755,7 +2755,7 @@ static void communicate_with_listener_v1(struct tracecmd_msg_handle *msg_handle) /* No options */ write(msg_handle->fd, "0", 2); - client_ports = malloc(sizeof(int) * local_cpu_count); + client_ports = malloc(local_cpu_count * sizeof(*client_ports)); if (!client_ports) die("Failed to allocate client ports for %d cpus", local_cpu_count); -- 2.19.1
![]() |