Commit 7ef9c608 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Alessandro Rubini

userspace/spll_dbg_proxy: fixed segfault on ring buffer overflow

parent b9e7a568
...@@ -70,6 +70,8 @@ void rbuf_push(struct ring_buffer *rbuf, void *what) ...@@ -70,6 +70,8 @@ void rbuf_push(struct ring_buffer *rbuf, void *what)
rbuf->count++; rbuf->count++;
memcpy(rbuf->base + rbuf->wr_ptr*rbuf->entry_size, what, rbuf->entry_size); memcpy(rbuf->base + rbuf->wr_ptr*rbuf->entry_size, what, rbuf->entry_size);
rbuf->wr_ptr++; rbuf->wr_ptr++;
if(rbuf->wr_ptr == rbuf->num_entries)
rbuf->wr_ptr = 0;
} }
int rbuf_pop(struct ring_buffer *rbuf, void *dst) int rbuf_pop(struct ring_buffer *rbuf, void *dst)
...@@ -80,6 +82,9 @@ int rbuf_pop(struct ring_buffer *rbuf, void *dst) ...@@ -80,6 +82,9 @@ int rbuf_pop(struct ring_buffer *rbuf, void *dst)
rbuf->count--; rbuf->count--;
memcpy(dst, rbuf->base + rbuf->rd_ptr*rbuf->entry_size, rbuf->entry_size); memcpy(dst, rbuf->base + rbuf->rd_ptr*rbuf->entry_size, rbuf->entry_size);
rbuf->rd_ptr++; rbuf->rd_ptr++;
if(rbuf->rd_ptr == rbuf->num_entries)
rbuf->rd_ptr = 0;
return 1; return 1;
} }
...@@ -145,10 +150,10 @@ void proxy_stuff(int fd) ...@@ -145,10 +150,10 @@ void proxy_stuff(int fd)
if( rbuf_init(&spll_trace, RING_BUFFER_ENTRIES, sizeof(struct fifo_entry)) < 0) if( rbuf_init(&spll_trace, RING_BUFFER_ENTRIES, sizeof(struct fifo_entry)) < 0)
{ {
perror("rbuf_init()"); perror("rbuf_init()");
return -1; return ;
} }
fprintf(stderr,"Connection accepted.\n"); fprintf(stderr,"Connection accepted [record size %d].\n", sizeof(struct fifo_entry));
proxy_done = 0; proxy_done = 0;
signal(SIGPIPE, sighandler); signal(SIGPIPE, sighandler);
......
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