File expat-CVE-2024-50602.patch of Package expat.36377
From 51c7019069b862e88d94ed228659e70bddd5de09 Mon Sep 17 00:00:00 2001
From: Sebastian Pipping <sebastian@pipping.org>
Date: Mon, 21 Oct 2024 01:42:54 +0200
Subject: [PATCH 1/3] lib: Make XML_StopParser refuse to stop/suspend an
unstarted parser
---
expat/lib/expat.h | 4 +++-
expat/lib/xmlparse.c | 6 ++++++
2 files changed, 9 insertions(+), 1 deletion(-)
Index: expat-2.1.0/lib/expat.h
===================================================================
--- expat-2.1.0.orig/lib/expat.h
+++ expat-2.1.0/lib/expat.h
@@ -96,7 +96,9 @@ enum XML_Error {
XML_ERROR_RESERVED_PREFIX_XML,
XML_ERROR_RESERVED_PREFIX_XMLNS,
XML_ERROR_RESERVED_NAMESPACE_URI,
- XML_ERROR_INVALID_ARGUMENT
+ XML_ERROR_INVALID_ARGUMENT,
+ /* Added in 2.6.4. */
+ XML_ERROR_NOT_STARTED,
};
enum XML_Content_Type {
Index: expat-2.1.0/lib/xmlparse.c
===================================================================
--- expat-2.1.0.orig/lib/xmlparse.c
+++ expat-2.1.0/lib/xmlparse.c
@@ -1880,6 +1880,9 @@ enum XML_Status XMLCALL
XML_StopParser(XML_Parser parser, XML_Bool resumable)
{
switch (ps_parsing) {
+ case XML_INITIALIZED:
+ parser->m_errorCode = XML_ERROR_NOT_STARTED;
+ return XML_STATUS_ERROR;
case XML_SUSPENDED:
if (resumable) {
errorCode = XML_ERROR_SUSPENDED;
@@ -1890,7 +1893,7 @@ XML_StopParser(XML_Parser parser, XML_Bo
case XML_FINISHED:
errorCode = XML_ERROR_FINISHED;
return XML_STATUS_ERROR;
- default:
+ case XML_PARSING:
if (resumable) {
#ifdef XML_DTD
if (isParamEntity) {
@@ -1902,6 +1905,9 @@ XML_StopParser(XML_Parser parser, XML_Bo
}
else
ps_parsing = XML_FINISHED;
+ break;
+ default:
+ assert(0);
}
return XML_STATUS_OK;
}
@@ -2089,7 +2095,8 @@ XML_ErrorString(enum XML_Error code)
XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name"),
XML_L("reserved prefix (xmlns) must not be declared or undeclared"),
XML_L("prefix must not be bound to one of the reserved namespace names"),
- XML_L("invalid argument")
+ XML_L("invalid argument"),
+ XML_L("parser not started")
};
if (code > 0 && code < sizeof(message)/sizeof(message[0]))
return message[code];