Commit d067cff7 authored by Joanne Hugé's avatar Joanne Hugé

Fix segmentation fault caused by incorrectly accessing the cyclic timestamp buffer

parent 53fd7c47
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include "common.h" #include "common.h"
#include "send_packet.h" #include "send_packet.h"
#define TIMESTAMP_BUFFER_SIZE 64
static void *poll_thread(void *p); static void *poll_thread(void *p);
static void process_error_queue(); static void process_error_queue();
...@@ -56,7 +58,7 @@ static struct sock_txtime sk_txtime; ...@@ -56,7 +58,7 @@ static struct sock_txtime sk_txtime;
static char *tx_buffer; static char *tx_buffer;
static int sock_fd; static int sock_fd;
static uint64_t timestamps_buffer[64]; static uint64_t timestamps_buffer[TIMESTAMP_BUFFER_SIZE];
static int ts_buf_read_index = 0; static int ts_buf_read_index = 0;
static int ts_buf_write_index = 0; static int ts_buf_write_index = 0;
...@@ -129,7 +131,7 @@ void send_udp_packet(char *data, ...@@ -129,7 +131,7 @@ void send_udp_packet(char *data,
if (params->use_timestamps) { if (params->use_timestamps) {
clock_gettime(CLOCK_REALTIME, &ts); clock_gettime(CLOCK_REALTIME, &ts);
timestamps_buffer[ts_buf_write_index++] = ts_to_uint(ts); timestamps_buffer[(ts_buf_write_index++) % TIMESTAMP_BUFFER_SIZE] = ts_to_uint(ts);
} }
packets_sent++; packets_sent++;
...@@ -220,7 +222,7 @@ static void process_error_queue() { ...@@ -220,7 +222,7 @@ static void process_error_queue() {
struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg); struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg);
int kernel_latency = (ts_to_uint(*stamp) - timestamps_buffer[ts_buf_read_index++]) / 1000; int kernel_latency = (ts_to_uint(*stamp) - timestamps_buffer[(ts_buf_read_index++) % TIMESTAMP_BUFFER_SIZE]) / 1000;
stats->min_kernel_latency = min(kernel_latency, stats->min_kernel_latency); stats->min_kernel_latency = min(kernel_latency, stats->min_kernel_latency);
stats->max_kernel_latency = max(kernel_latency, stats->max_kernel_latency); stats->max_kernel_latency = max(kernel_latency, stats->max_kernel_latency);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment