Skip to content

Commit

Permalink
_CFXMLInterface: account for possible nullptr return
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
compnerd committed Sep 9, 2024
1 parent a12c7d1 commit 9cae1fa
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/_CFXMLInterface/CFXMLInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 9cae1fa

Please sign in to comment.