Skip to content

Commit 9cae1fa

Browse files
committed
_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.
1 parent a12c7d1 commit 9cae1fa

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Sources/_CFXMLInterface/CFXMLInterface.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,10 @@ CFStringRef _CFXMLNodeCopyPrefix(_CFXMLNodePtr node) {
10731073
xmlChar* result = NULL;
10741074
xmlChar* unused = xmlSplitQName2(_getQName((xmlNodePtr)node), &result);
10751075

1076-
CFStringRef resultString = __CFSwiftXMLParserBridgeCF.CFStringCreateWithCString(NULL, (const char*)result, kCFStringEncodingUTF8);
1076+
CFStringRef resultString = NULL;
1077+
if (result) {
1078+
resultString = __CFSwiftXMLParserBridgeCF.CFStringCreateWithCString(NULL, (const char*)result, kCFStringEncodingUTF8);
1079+
}
10771080
xmlFree(result);
10781081
xmlFree(unused);
10791082

0 commit comments

Comments
 (0)