From d.c.ddcc at gmail.com Sat May 6 04:37:26 2017 From: d.c.ddcc at gmail.com (Dominic Chen) Date: Sat, 6 May 2017 00:37:26 -0400 Subject: [PATCH] gr-osmosdr: Avoid crashing if number of connected channels is greater than maximum Message-ID: <8ab0beb9-c19a-b722-873b-631ad3e4f252@gmail.com> This is a workaround for a crash triggered by the following scenario: using gqrx, if the automatically generated device string "addr=1d50:6108,driver=lime,media='USB 3.0',module=STREAM,name=LimeSDR-USB,serial=XXXX,soapy=0" is passed into gr-osmosdr, args_to_io_signature(args) will generate an io_signature with two channels, because the space in 'USB 3.0' causes dev_nchan to be incremented twice. Then, in source_impl::source_impl(), GNU Radio will gneerate an exception of the form "FATAL: destination port 1 out of range for source_impl(47)", which causes the exception-handling null channel code to be executed. But, since output_signature()->max_streams() returns 1, channel is 2, and missing_chans has size_t type, the subtraction will underflow to (unsigned int)(-1), which causes another GNU Radio exception when connect(). Since this is an exception in an exception handler, the program will terminate immediately. Thanks, Dominic --- lib/source_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/source_impl.cc b/lib/source_impl.cc index a28f314..ac7c3af 100644 --- a/lib/source_impl.cc +++ b/lib/source_impl.cc @@ -426,7 +426,7 @@ source_impl::source_impl( const std::string &args ) connect(null_source, 0, throttle, 0); size_t missing_chans = 0; - if ( output_signature()->max_streams() > 0 ) + if ( output_signature()->max_streams() > 0 && ((size_t) output_signature()->max_streams()) > channel) missing_chans = output_signature()->max_streams() - channel; std::cerr << "Trying to fill up " << missing_chans -- 2.7.4