Repository navigation
buffer: do not call memcpy() with a NULL source for an empty append - #824
Open
1820893135-pixel wants to merge 1 commit into
Open
1820893135-pixel wants to merge 1 commit into
1820893135-pixel wants to merge 1 commit into
Conversation
An empty table cell reaches rndr_tablerow() with text->data == NULL and text->size == 0, and bufput() then calls memcpy(dst, NULL, 0). The source of memcpy() is declared nonnull, so that is undefined behavior even though no bytes move; UBSan reports it, and a trapping build aborts on a one-byte "|" document. Return early when len == 0, before the copy and the grow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #822.
Root cause
rndr_tablerow()callsbufput(ob, text->data, text->size)for an empty cell,which passes
data == NULLandlen == 0.bufput()then callsmemcpy(dst, NULL, 0); the source ofmemcpy()is declarednonnull, so thisis undefined behavior even though no bytes move:
With
-fno-sanitize-recover=all, the one-byte document containing a singlepipe character aborts.
Fix
Return early when
len == 0, before the grow and the copy.Verification
Build (no Ruby needed):
with the
driver.cfrom the report.buffer.c:169No behaviour change: rendered 71 documents (every
test/MarkdownTest_1.0*/Tests/*.textplus 30 autolink/table/blockquote cases)with the pristine and the patched build (plain
-O2); HTML output, stderr andexit status are byte-identical.