mirror of
https://github.com/libexpat/libexpat.git
synced 2025-04-15 00:38:15 +00:00
lib: Prevent integer overflow on m_groupSize in function doProlog (CVE-2021-46143)
This commit is contained in:
parent
b6b432bad5
commit
85ae9a2d7d
1 changed files with 15 additions and 0 deletions
|
@ -5046,6 +5046,11 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
|
|||
if (parser->m_prologState.level >= parser->m_groupSize) {
|
||||
if (parser->m_groupSize) {
|
||||
{
|
||||
/* Detect and prevent integer overflow */
|
||||
if (parser->m_groupSize > (unsigned int)(-1) / 2u) {
|
||||
return XML_ERROR_NO_MEMORY;
|
||||
}
|
||||
|
||||
char *const new_connector = (char *)REALLOC(
|
||||
parser, parser->m_groupConnector, parser->m_groupSize *= 2);
|
||||
if (new_connector == NULL) {
|
||||
|
@ -5056,6 +5061,16 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end,
|
|||
}
|
||||
|
||||
if (dtd->scaffIndex) {
|
||||
/* Detect and prevent integer overflow.
|
||||
* The preprocessor guard addresses the "always false" warning
|
||||
* from -Wtype-limits on platforms where
|
||||
* sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */
|
||||
#if UINT_MAX >= SIZE_MAX
|
||||
if (parser->m_groupSize > (size_t)(-1) / sizeof(int)) {
|
||||
return XML_ERROR_NO_MEMORY;
|
||||
}
|
||||
#endif
|
||||
|
||||
int *const new_scaff_index = (int *)REALLOC(
|
||||
parser, dtd->scaffIndex, parser->m_groupSize * sizeof(int));
|
||||
if (new_scaff_index == NULL)
|
||||
|
|
Loading…
Add table
Reference in a new issue