fix: harden OPDS parser cleanup after errors
Fix potential use-after-free or double-free issue in the OPDS parser by nulling it after free and guarding against using a nullptr parser in `flush()`.
This commit is contained in:
@@ -40,6 +40,7 @@ size_t OpdsParser::write(const uint8_t* xmlData, const size_t length) {
|
|||||||
if (!buf) {
|
if (!buf) {
|
||||||
errorOccured = true;
|
errorOccured = true;
|
||||||
XML_ParserFree(parser);
|
XML_ParserFree(parser);
|
||||||
|
parser = nullptr;
|
||||||
return length;
|
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) {
|
if (XML_ParseBuffer(parser, static_cast<int>(toRead), 0) == XML_STATUS_ERROR) {
|
||||||
errorOccured = true;
|
errorOccured = true;
|
||||||
XML_ParserFree(parser);
|
XML_ParserFree(parser);
|
||||||
|
parser = nullptr;
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
currentPos += toRead;
|
currentPos += toRead;
|
||||||
@@ -58,6 +60,10 @@ size_t OpdsParser::write(const uint8_t* xmlData, const size_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OpdsParser::flush() {
|
void OpdsParser::flush() {
|
||||||
|
if (!parser) {
|
||||||
|
errorOccured = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (XML_Parse(parser, nullptr, 0, XML_TRUE) != XML_STATUS_OK) {
|
if (XML_Parse(parser, nullptr, 0, XML_TRUE) != XML_STATUS_OK) {
|
||||||
errorOccured = true;
|
errorOccured = true;
|
||||||
XML_ParserFree(parser);
|
XML_ParserFree(parser);
|
||||||
|
|||||||
Reference in New Issue
Block a user