From: Uwe Hermann Date: Tue, 12 Nov 2019 21:47:41 +0000 (+0100) Subject: srd_decoder_doc_get(): Add an additional sanity check. X-Git-Url: http://sigrok.org/gitweb/?p=libsigrokdecode.git;a=commitdiff_plain;h=f8c24e2e58ee76e6bdc50b87060e2efb7e8838ba srd_decoder_doc_get(): Add an additional sanity check. --- diff --git a/decoder.c b/decoder.c index 5239818..cef4f29 100644 --- a/decoder.c +++ b/decoder.c @@ -869,7 +869,7 @@ err_out: /** * Return a protocol decoder's docstring. * - * @param dec The loaded protocol decoder. + * @param dec The loaded protocol decoder. Must not be NULL. * * @return A newly allocated buffer containing the protocol decoder's * 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) if (!srd_check_init()) return NULL; - if (!dec) + if (!dec || !dec->py_mod) return NULL; gstate = PyGILState_Ensure(); diff --git a/tests/decoder.c b/tests/decoder.c index 3678410..3acabae 100644 --- a/tests/decoder.c +++ b/tests/decoder.c @@ -404,11 +404,19 @@ END_TEST * Check whether srd_decoder_doc_get() fails with NULL as argument. * If it returns a value != NULL (or segfaults) this test will fail. * See also: http://sigrok.org/bugzilla/show_bug.cgi?id=179 + * Check whether srd_decoder_doc_get() fails with dec->py_mod == NULL. + * If it returns a value != NULL (or segfaults) this test will fail. + * See also: http://sigrok.org/bugzilla/show_bug.cgi?id=180 */ START_TEST(test_doc_get_null) { + struct srd_decoder dec; + + dec.py_mod = NULL; + srd_init(DECODERS_TESTDIR); fail_unless(srd_decoder_doc_get(NULL) == NULL); + fail_unless(srd_decoder_doc_get(&dec) == NULL); srd_exit(); } END_TEST