Skip to content

Require a single text child for LaTeX autolinks - #670

Open
sagaragas wants to merge 1 commit into
commonmark:masterfrom
sagaragas:latex-autolink-text-only
Open

sagaragas wants to merge 1 commit into
commonmark:masterfrom
sagaragas:latex-autolink-text-only

Conversation

@sagaragas

Copy link
Copy Markdown
Contributor

get_link_type() in src/latex.c compares the URL against a link's first child without checking that it's a single text node, so non-autolink inputs match. On [*a*](mailto:), it passes NULL to strncmp() (undefined behavior, caught by UBSan) and wraps \emph{a} in \nolinkurl{} when execution continues. Trailing inlines like [http://example.com*foo*](http://example.com) drop *foo* (or wrap it in \nolinkurl{} on mailto: links), and [`http://example.com`](http://example.com) drops \texttt{} because CMARK_NODE_CODE also sets data and len.

I updated get_link_type() to require a single CMARK_NODE_TEXT child and a positive remaining URL length, and added regression cases in api_test/main.c. All seven bug cases fail on master. Plain autolinks stay intact, and the static and shared ctest suites pass under ASan, UBSan, and Release.

get_link_type() in src/latex.c compared the URL against the first
child's data and len without checking that the child is a single
CMARK_NODE_TEXT node with a non-empty destination. On [*a*](mailto:),
that passed NULL to strncmp() (C undefined behavior, caught by UBSan)
and wrapped \emph{a} in \nolinkurl{} when execution continued. Links
with trailing inlines like [http://example.com*foo*](http://example.com)
dropped *foo* (or wrapped it in \nolinkurl{} for mailto:), and code-span
links like [`http://example.com`](http://example.com) dropped \texttt{}
because CMARK_NODE_CODE also populates data and len. Check that
link_text is the sole child with type CMARK_NODE_TEXT and that
realurllen > 0 before calling strncmp(), and add regression cases to
render_latex in api_test/main.c.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant