Skip to content

Commit f8c24e2

Browse files
committed
srd_decoder_doc_get(): Add an additional sanity check.
1 parent 5d6d889 commit f8c24e2

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

decoder.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ SRD_API int srd_decoder_load(const char *module_name)
869869
/**
870870
* Return a protocol decoder's docstring.
871871
*
872-
* @param dec The loaded protocol decoder.
872+
* @param dec The loaded protocol decoder. Must not be NULL.
873873
*
874874
* @return A newly allocated buffer containing the protocol decoder's
875875
* documentation. The caller is responsible for free'ing the buffer.
@@ -885,7 +885,7 @@ SRD_API char *srd_decoder_doc_get(const struct srd_decoder *dec)
885885
if (!srd_check_init())
886886
return NULL;
887887

888-
if (!dec)
888+
if (!dec || !dec->py_mod)
889889
return NULL;
890890

891891
gstate = PyGILState_Ensure();

tests/decoder.c

+8
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,19 @@ END_TEST
404404
* Check whether srd_decoder_doc_get() fails with NULL as argument.
405405
* If it returns a value != NULL (or segfaults) this test will fail.
406406
* See also: http://sigrok.org/bugzilla/show_bug.cgi?id=179
407+
* Check whether srd_decoder_doc_get() fails with dec->py_mod == NULL.
408+
* If it returns a value != NULL (or segfaults) this test will fail.
409+
* See also: http://sigrok.org/bugzilla/show_bug.cgi?id=180
407410
*/
408411
START_TEST(test_doc_get_null)
409412
{
413+
struct srd_decoder dec;
414+
415+
dec.py_mod = NULL;
416+
410417
srd_init(DECODERS_TESTDIR);
411418
fail_unless(srd_decoder_doc_get(NULL) == NULL);
419+
fail_unless(srd_decoder_doc_get(&dec) == NULL);
412420
srd_exit();
413421
}
414422
END_TEST

0 commit comments

Comments
 (0)