Merge pull request #105 from jgoguen/fix-parser-use-after-free
fix: harden OPDS parser cleanup after errors
This commit is contained in:
@@ -40,6 +40,7 @@ size_t OpdsParser::write(const uint8_t* xmlData, const size_t length) {
|
||||
if (!buf) {
|
||||
errorOccured = true;
|
||||
XML_ParserFree(parser);
|
||||
parser = nullptr;
|
||||
return length;
|
||||
}
|
||||
|
||||
@@ -49,6 +50,7 @@ size_t OpdsParser::write(const uint8_t* xmlData, const size_t length) {
|
||||
if (XML_ParseBuffer(parser, static_cast<int>(toRead), 0) == XML_STATUS_ERROR) {
|
||||
errorOccured = true;
|
||||
XML_ParserFree(parser);
|
||||
parser = nullptr;
|
||||
return length;
|
||||
}
|
||||
currentPos += toRead;
|
||||
@@ -58,6 +60,10 @@ size_t OpdsParser::write(const uint8_t* xmlData, const size_t length) {
|
||||
}
|
||||
|
||||
void OpdsParser::flush() {
|
||||
if (!parser) {
|
||||
errorOccured = true;
|
||||
return;
|
||||
}
|
||||
if (XML_Parse(parser, nullptr, 0, XML_TRUE) != XML_STATUS_OK) {
|
||||
errorOccured = true;
|
||||
XML_ParserFree(parser);
|
||||
|
||||
Reference in New Issue
Block a user