Skip to content

Commit b38ab79

Browse files
karen-arutyunovboris-kolpackov
authored andcommitted
XERCESC-2188 - Use-after-free on external DTD scan (CVE-2018-1311)
These are the instructions for observing the bug (before this commit): $ git clone https://github.com/apache/xerces-c.git $ cd xerces-c $ mkdir build $ cd build $ cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug .. $ make -j8 $ cp ../samples/data/personal.xml . $ cat <<EOF >personal.dtd <?xml encoding="ISO-8859-1"?> <!ENTITY % nonExistentEntity SYSTEM "non-existent.ent"> %nonExistentEntity; EOF $ gdb samples/StdInParse (gdb) b IGXMLScanner.cpp:1544 (gdb) run <personal.xml 1544 fReaderMgr.pushReader(reader, declDTD); (gdb) p declDTD $1 = (xercesc_4_0::DTDEntityDecl *) 0x49ac68 (gdb) n 1547 dtdScanner.scanExtSubsetDecl(false, true); (gdb) n 1548 } (gdb) s ... (gdb) s # The Janitor is about to delete the above declDTD. 90 delete fData; (gdb) p fData $1 = (xercesc_4_0::DTDEntityDecl *) 0x49ac68 (gdb) b ReaderMgr.cpp:1024 (gdb) n ... (gdb) n # Now we about to dereference the deleted declDTD. 1024 if (curEntity && !curEntity->isExternal()) (gdb) p curEntity $2 = (const xercesc_4_0::XMLEntityDecl *) 0x49ac68
1 parent 5b31900 commit b38ab79

File tree

4 files changed

+229
-82
lines changed

4 files changed

+229
-82
lines changed

src/xercesc/internal/DGXMLScanner.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,13 +1052,12 @@ void DGXMLScanner::scanDocTypeDecl()
10521052
DTDEntityDecl* declDTD = new (fMemoryManager) DTDEntityDecl(gDTDStr, false, fMemoryManager);
10531053
declDTD->setSystemId(sysId);
10541054
declDTD->setIsExternal(true);
1055-
Janitor<DTDEntityDecl> janDecl(declDTD);
10561055

10571056
// Mark this one as a throw at end
10581057
reader->setThrowAtEnd(true);
10591058

10601059
// And push it onto the stack, with its pseudo name
1061-
fReaderMgr.pushReader(reader, declDTD);
1060+
fReaderMgr.pushReaderAdoptEntity(reader, declDTD);
10621061

10631062
// Tell it its not in an include section
10641063
dtdScanner.scanExtSubsetDecl(false, true);
@@ -2131,13 +2130,12 @@ Grammar* DGXMLScanner::loadDTDGrammar(const InputSource& src,
21312130
DTDEntityDecl* declDTD = new (fMemoryManager) DTDEntityDecl(gDTDStr, false, fMemoryManager);
21322131
declDTD->setSystemId(src.getSystemId());
21332132
declDTD->setIsExternal(true);
2134-
Janitor<DTDEntityDecl> janDecl(declDTD);
21352133

21362134
// Mark this one as a throw at end
21372135
newReader->setThrowAtEnd(true);
21382136

21392137
// And push it onto the stack, with its pseudo name
2140-
fReaderMgr.pushReader(newReader, declDTD);
2138+
fReaderMgr.pushReaderAdoptEntity(newReader, declDTD);
21412139

21422140
// If we have a doc type handler and advanced callbacks are enabled,
21432141
// call the doctype event.

src/xercesc/internal/IGXMLScanner.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,13 +1535,12 @@ void IGXMLScanner::scanDocTypeDecl()
15351535
DTDEntityDecl* declDTD = new (fMemoryManager) DTDEntityDecl(gDTDStr, false, fMemoryManager);
15361536
declDTD->setSystemId(sysId);
15371537
declDTD->setIsExternal(true);
1538-
Janitor<DTDEntityDecl> janDecl(declDTD);
15391538

15401539
// Mark this one as a throw at end
15411540
reader->setThrowAtEnd(true);
15421541

15431542
// And push it onto the stack, with its pseudo name
1544-
fReaderMgr.pushReader(reader, declDTD);
1543+
fReaderMgr.pushReaderAdoptEntity(reader, declDTD);
15451544

15461545
// Tell it its not in an include section
15471546
dtdScanner.scanExtSubsetDecl(false, true);
@@ -3098,13 +3097,12 @@ Grammar* IGXMLScanner::loadDTDGrammar(const InputSource& src,
30983097
DTDEntityDecl* declDTD = new (fMemoryManager) DTDEntityDecl(gDTDStr, false, fMemoryManager);
30993098
declDTD->setSystemId(src.getSystemId());
31003099
declDTD->setIsExternal(true);
3101-
Janitor<DTDEntityDecl> janDecl(declDTD);
31023100

31033101
// Mark this one as a throw at end
31043102
newReader->setThrowAtEnd(true);
31053103

31063104
// And push it onto the stack, with its pseudo name
3107-
fReaderMgr.pushReader(newReader, declDTD);
3105+
fReaderMgr.pushReaderAdoptEntity(newReader, declDTD);
31083106

31093107
// If we have a doc type handler and advanced callbacks are enabled,
31103108
// call the doctype event.

0 commit comments

Comments
 (0)