Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Commit

Permalink
Missing NULL-check caused segfault.
Browse files Browse the repository at this point in the history
  • Loading branch information
FSX committed Dec 1, 2018
1 parent cc9021e commit 25ad527
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions misaka/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def cb_footnote_def(ob, content, num, data):
' const hoedown_renderer_data *data)')
def cb_blockhtml(ob, text, data):
renderer = ffi.from_handle(lib.misaka_get_renderer(data))
text = ffi.string(text.data, text.size).decode('utf-8')
text = to_string(text)
result = renderer.blockhtml(text)
if result:
lib.hoedown_buffer_puts(ob, result.encode('utf-8'))
Expand All @@ -184,7 +184,7 @@ def cb_blockhtml(ob, text, data):
' hoedown_autolink_type type, const hoedown_renderer_data *data)')
def cb_autolink(ob, link, type, data):
renderer = ffi.from_handle(lib.misaka_get_renderer(data))
link = ffi.string(link.data, link.size).decode('utf-8')
link = to_string(link)
is_email = int(type) & AUTOLINK_EMAIL != 0
result = renderer.autolink(link, is_email)
if result:
Expand All @@ -197,7 +197,7 @@ def cb_autolink(ob, link, type, data):
' const hoedown_renderer_data *data)')
def cb_codespan(ob, text, data):
renderer = ffi.from_handle(lib.misaka_get_renderer(data))
text = ffi.string(text.data, text.size).decode('utf-8')
text = to_string(text)
result = renderer.codespan(text)
if result:
lib.hoedown_buffer_puts(ob, result.encode('utf-8'))
Expand Down
21 changes: 21 additions & 0 deletions tests/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,24 @@ def test():

test.__name__ = 'test_' + name
self.add_test(test)


class BugRenderer(m.BaseRenderer):
def __init__(self):
m.BaseRenderer.__init__(self)

def codespan(self, text):
return '(' + text + ')'

def normal_text(self, text):
return text

def paragraph(self, content):
return content


class TestBugs(TestCase):
def test_empty_span(self):
# See: https://github.com/FSX/misaka/issues/67
md = m.Markdown(BugRenderer())
md("` `")

0 comments on commit 25ad527

Please sign in to comment.