Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_CFXMLInterface: account for possible nullptr return #5082

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
_CFXMLInterface: account for possible nullptr return
`xmlSplitQName2` may return `nullptr` for the result, which when passed
to `CFStringCreateWithCString` would attempt to perform
`strlen(nullptr)` which is ill-defined. When updating libxml2 on
Windows, we would perform an invalid memory access due to the `strlen`
invocation inside `CFStringCreateWithCString`. Protect against this
case, returning `NULL` instead.
compnerd committed Sep 9, 2024

Verified

This commit was signed with the committer’s verified signature.
commit 9cae1fae6a6d14d4e788b2587b91bf61b26cedfa
5 changes: 4 additions & 1 deletion Sources/_CFXMLInterface/CFXMLInterface.c
Original file line number Diff line number Diff line change
@@ -1073,7 +1073,10 @@ CFStringRef _CFXMLNodeCopyPrefix(_CFXMLNodePtr node) {
xmlChar* result = NULL;
xmlChar* unused = xmlSplitQName2(_getQName((xmlNodePtr)node), &result);

CFStringRef resultString = __CFSwiftXMLParserBridgeCF.CFStringCreateWithCString(NULL, (const char*)result, kCFStringEncodingUTF8);
CFStringRef resultString = NULL;
if (result) {
resultString = __CFSwiftXMLParserBridgeCF.CFStringCreateWithCString(NULL, (const char*)result, kCFStringEncodingUTF8);
}
xmlFree(result);
xmlFree(unused);