Skip to content

Commit

Permalink
Merge pull request #1252 from gqrx-sdr/fix-sniffer-buffer-overflow
Browse files Browse the repository at this point in the history
Fix buffer overflow in sniffer block
  • Loading branch information
argilo authored Jun 1, 2023
2 parents cd5cc66 + 96101db commit 996737c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions resources/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
IMPROVED: Waterfall span setting is stored in milliseconds.
FIXED: Time on waterfall is calculated correctly.
FIXED: Frequency is correctly rounded in I/Q filenames.
FIXED: Crash in AFSK1200 decoder.


2.16: Released April 28, 2023
Expand Down
7 changes: 4 additions & 3 deletions src/dsp/sniffer_f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ sniffer_f::sniffer_f(int buffsize)
: gr::sync_block ("sniffer_f",
gr::io_signature::make(1, 1, sizeof(float)),
gr::io_signature::make(0, 0, 0)),
d_buffsize(buffsize),
d_minsamp(1000)
{

/* allocate circular buffer */
#if GNURADIO_VERSION < 0x031000
d_writer = gr::make_buffer(buffsize, sizeof(float));
d_writer = gr::make_buffer(d_buffsize, sizeof(float));
#else
d_writer = gr::make_buffer(buffsize, sizeof(float), 1, 1);
d_writer = gr::make_buffer(d_buffsize, sizeof(float), 1, 1);
#endif
d_reader = gr::buffer_add_reader(d_writer, 0);

Expand Down Expand Up @@ -122,7 +123,7 @@ void sniffer_f::get_samples(float * out, unsigned int &num)
return;
}

num = d_reader->items_available();
num = std::min(d_reader->items_available(), d_buffsize);
memcpy(out, d_reader->read_pointer(), sizeof(float)*num);
d_reader->update_read_pointer(num);
}
Expand Down
1 change: 1 addition & 0 deletions src/dsp/sniffer_f.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class sniffer_f : public gr::sync_block
std::mutex d_mutex; /*! Used to prevent concurrent access to buffer. */
gr::buffer_sptr d_writer;
gr::buffer_reader_sptr d_reader;
int d_buffsize;
unsigned int d_minsamp; /*! smallest number of samples we want to return. */

};
Expand Down

0 comments on commit 996737c

Please sign in to comment.