mirror of https://github.com/AxioDL/tinyxml2.git
Resolve crash when printing malformed entities - issue 291
This commit is contained in:
parent
0f922e7c9a
commit
6f51c803a1
12
tinyxml2.cpp
12
tinyxml2.cpp
|
@ -228,12 +228,20 @@ const char* StrPair::GetStr()
|
||||||
const int buflen = 10;
|
const int buflen = 10;
|
||||||
char buf[buflen] = { 0 };
|
char buf[buflen] = { 0 };
|
||||||
int len = 0;
|
int len = 0;
|
||||||
p = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
|
char* adjusted = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
|
||||||
|
if ( adjusted == 0 ) {
|
||||||
|
*q = *p;
|
||||||
|
++p;
|
||||||
|
++q;
|
||||||
|
}
|
||||||
|
else {
|
||||||
TIXMLASSERT( 0 <= len && len <= buflen );
|
TIXMLASSERT( 0 <= len && len <= buflen );
|
||||||
TIXMLASSERT( q + len <= p );
|
TIXMLASSERT( q + len <= adjusted );
|
||||||
|
p = adjusted;
|
||||||
memcpy( q, buf, len );
|
memcpy( q, buf, len );
|
||||||
q += len;
|
q += len;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
int i=0;
|
int i=0;
|
||||||
for(; i<NUM_ENTITIES; ++i ) {
|
for(; i<NUM_ENTITIES; ++i ) {
|
||||||
|
|
10
xmltest.cpp
10
xmltest.cpp
|
@ -1416,6 +1416,16 @@ int main( int argc, const char ** argv )
|
||||||
XMLPrinter printer;
|
XMLPrinter printer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Issue 291. Should not crash
|
||||||
|
const char* xml = "�</a>";
|
||||||
|
XMLDocument doc;
|
||||||
|
doc.Parse( xml );
|
||||||
|
|
||||||
|
XMLPrinter printer;
|
||||||
|
doc.Print( &printer );
|
||||||
|
}
|
||||||
|
|
||||||
// ----------- Performance tracking --------------
|
// ----------- Performance tracking --------------
|
||||||
{
|
{
|
||||||
#if defined( _MSC_VER )
|
#if defined( _MSC_VER )
|
||||||
|
|
Loading…
Reference in New Issue