From e48a1310fe0d274e26aa220caf67c12761eaea4c Mon Sep 17 00:00:00 2001 From: sbaluja <114016489+sbaluja@users.noreply.github.com> Date: Mon, 9 Mar 2026 20:31:36 -0400 Subject: [PATCH 1/2] Add null check for format in TIXML_VSCPRINTF (#1064) --- tinyxml2.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 50e6e2a..35e7703 100644 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -114,6 +114,9 @@ distribution. #define TIXML_VSNPRINTF vsnprintf static inline int TIXML_VSCPRINTF( const char* format, va_list va ) { + if (!format) { + return 0; + } int len = vsnprintf( 0, 0, format, va ); TIXMLASSERT( len >= 0 ); return len; From aba13c50bf7ec2d0a8e47719ceda264b27297240 Mon Sep 17 00:00:00 2001 From: zhthhh <130774630+zhthhh@users.noreply.github.com> Date: Tue, 10 Mar 2026 08:32:22 +0800 Subject: [PATCH 2/2] Fix issue #1048: Add null pointer check in XMLDocument::DeleteNode (#1057) - Add null pointer check in XMLDocument::DeleteNode() method - Add test case to verify null pointer handling - Prevents segmentation fault when calling DeleteNode(nullptr) --- tinyxml2.cpp | 5 ++++- xmltest.cpp | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 35e7703..a0a0b23 100644 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -2347,9 +2347,12 @@ static FILE* callfopen( const char* filepath, const char* mode ) return fp; } -void XMLDocument::DeleteNode( XMLNode* node ) { +void XMLDocument::DeleteNode( XMLNode* node ) { TIXMLASSERT( node ); TIXMLASSERT(node->_document == this ); + if(node == 0) { + return; // check for null pointer + } if (node->_parent) { node->_parent->DeleteChild( node ); } diff --git a/xmltest.cpp b/xmltest.cpp index 8a654e4..d058707 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -2025,7 +2025,13 @@ int main( int argc, const char ** argv ) XMLTest("Parse nested elements with pedantic whitespace", false, doc.Error()); XMLTest("Pedantic whitespace", true, 0 == doc.RootElement()->FirstChildElement()->GetText()); } - + //Check the robustness of the DeleteNode function in handling null pointers. + { + XMLDocument doc; + doc.DeleteNode(nullptr); + XMLTest("DeleteNode with null pointer", true, doc.Error() == XML_SUCCESS); + } + // Check sample xml can be parsed with pedantic mode { XMLDocument doc(true, PEDANTIC_WHITESPACE);