1
- /* 2a14271ad4d35e82bde8ba210b4edb7998794bcbae54deab114046a300f9639a (2.6.2 +)
1
+ /* ba4cdf9bdb534f355a9def4c9e25d20ee8e72f95b0a4d930be52e563f5080196 (2.6.3 +)
2
2
__ __ _
3
3
___\ \/ /_ __ __ _| |_
4
4
/ _ \\ /| '_ \ / _` | __|
39
39
Copyright (c) 2022 Sean McBride <[email protected] >
40
40
Copyright (c) 2023 Owain Davies <[email protected] >
41
41
Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <[email protected] >
42
+ Copyright (c) 2024 Berkay Eren Ürün <[email protected] >
42
43
Licensed under the MIT license:
43
44
44
45
Permission is hereby granted, free of charge, to any person obtaining
@@ -294,7 +295,7 @@ typedef struct {
294
295
The name of the element is stored in both the document and API
295
296
encodings. The memory buffer 'buf' is a separately-allocated
296
297
memory area which stores the name. During the XML_Parse()/
297
- XMLParseBuffer () when the element is open, the memory for the 'raw'
298
+ XML_ParseBuffer () when the element is open, the memory for the 'raw'
298
299
version of the name (in the document encoding) is shared with the
299
300
document buffer. If the element is open across calls to
300
301
XML_Parse()/XML_ParseBuffer(), the buffer is re-allocated to
@@ -2038,6 +2039,12 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal) {
2038
2039
2039
2040
if (parser == NULL )
2040
2041
return XML_STATUS_ERROR ;
2042
+
2043
+ if (len < 0 ) {
2044
+ parser -> m_errorCode = XML_ERROR_INVALID_ARGUMENT ;
2045
+ return XML_STATUS_ERROR ;
2046
+ }
2047
+
2041
2048
switch (parser -> m_parsingStatus .parsing ) {
2042
2049
case XML_SUSPENDED :
2043
2050
parser -> m_errorCode = XML_ERROR_SUSPENDED ;
@@ -5846,18 +5853,17 @@ processInternalEntity(XML_Parser parser, ENTITY *entity, XML_Bool betweenDecl) {
5846
5853
/* Set a safe default value in case 'next' does not get set */
5847
5854
next = textStart ;
5848
5855
5849
- #ifdef XML_DTD
5850
5856
if (entity -> is_param ) {
5851
5857
int tok
5852
5858
= XmlPrologTok (parser -> m_internalEncoding , textStart , textEnd , & next );
5853
5859
result = doProlog (parser , parser -> m_internalEncoding , textStart , textEnd ,
5854
5860
tok , next , & next , XML_FALSE , XML_FALSE ,
5855
5861
XML_ACCOUNT_ENTITY_EXPANSION );
5856
- } else
5857
- #endif /* XML_DTD */
5862
+ } else {
5858
5863
result = doContent (parser , parser -> m_tagLevel , parser -> m_internalEncoding ,
5859
5864
textStart , textEnd , & next , XML_FALSE ,
5860
5865
XML_ACCOUNT_ENTITY_EXPANSION );
5866
+ }
5861
5867
5862
5868
if (result == XML_ERROR_NONE ) {
5863
5869
if (textEnd != next && parser -> m_parsingStatus .parsing == XML_SUSPENDED ) {
@@ -5894,18 +5900,17 @@ internalEntityProcessor(XML_Parser parser, const char *s, const char *end,
5894
5900
/* Set a safe default value in case 'next' does not get set */
5895
5901
next = textStart ;
5896
5902
5897
- #ifdef XML_DTD
5898
5903
if (entity -> is_param ) {
5899
5904
int tok
5900
5905
= XmlPrologTok (parser -> m_internalEncoding , textStart , textEnd , & next );
5901
5906
result = doProlog (parser , parser -> m_internalEncoding , textStart , textEnd ,
5902
5907
tok , next , & next , XML_FALSE , XML_TRUE ,
5903
5908
XML_ACCOUNT_ENTITY_EXPANSION );
5904
- } else
5905
- #endif /* XML_DTD */
5909
+ } else {
5906
5910
result = doContent (parser , openEntity -> startTagLevel ,
5907
5911
parser -> m_internalEncoding , textStart , textEnd , & next ,
5908
5912
XML_FALSE , XML_ACCOUNT_ENTITY_EXPANSION );
5913
+ }
5909
5914
5910
5915
if (result != XML_ERROR_NONE )
5911
5916
return result ;
@@ -5932,17 +5937,14 @@ internalEntityProcessor(XML_Parser parser, const char *s, const char *end,
5932
5937
return XML_ERROR_NONE ;
5933
5938
}
5934
5939
5935
- #ifdef XML_DTD
5936
5940
if (entity -> is_param ) {
5937
5941
int tok ;
5938
5942
parser -> m_processor = prologProcessor ;
5939
5943
tok = XmlPrologTok (parser -> m_encoding , s , end , & next );
5940
5944
return doProlog (parser , parser -> m_encoding , s , end , tok , next , nextPtr ,
5941
5945
(XML_Bool )! parser -> m_parsingStatus .finalBuffer , XML_TRUE ,
5942
5946
XML_ACCOUNT_DIRECT );
5943
- } else
5944
- #endif /* XML_DTD */
5945
- {
5947
+ } else {
5946
5948
parser -> m_processor = contentProcessor ;
5947
5949
/* see externalEntityContentProcessor vs contentProcessor */
5948
5950
result = doContent (parser , parser -> m_parentParser ? 1 : 0 ,
@@ -7016,6 +7018,16 @@ dtdCopy(XML_Parser oldParser, DTD *newDtd, const DTD *oldDtd,
7016
7018
if (! newE )
7017
7019
return 0 ;
7018
7020
if (oldE -> nDefaultAtts ) {
7021
+ /* Detect and prevent integer overflow.
7022
+ * The preprocessor guard addresses the "always false" warning
7023
+ * from -Wtype-limits on platforms where
7024
+ * sizeof(int) < sizeof(size_t), e.g. on x86_64. */
7025
+ #if UINT_MAX >= SIZE_MAX
7026
+ if ((size_t )oldE -> nDefaultAtts
7027
+ > ((size_t )(-1 ) / sizeof (DEFAULT_ATTRIBUTE ))) {
7028
+ return 0 ;
7029
+ }
7030
+ #endif
7019
7031
newE -> defaultAtts
7020
7032
= ms -> malloc_fcn (oldE -> nDefaultAtts * sizeof (DEFAULT_ATTRIBUTE ));
7021
7033
if (! newE -> defaultAtts ) {
@@ -7558,6 +7570,15 @@ nextScaffoldPart(XML_Parser parser) {
7558
7570
int next ;
7559
7571
7560
7572
if (! dtd -> scaffIndex ) {
7573
+ /* Detect and prevent integer overflow.
7574
+ * The preprocessor guard addresses the "always false" warning
7575
+ * from -Wtype-limits on platforms where
7576
+ * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */
7577
+ #if UINT_MAX >= SIZE_MAX
7578
+ if (parser -> m_groupSize > ((size_t )(-1 ) / sizeof (int ))) {
7579
+ return -1 ;
7580
+ }
7581
+ #endif
7561
7582
dtd -> scaffIndex = (int * )MALLOC (parser , parser -> m_groupSize * sizeof (int ));
7562
7583
if (! dtd -> scaffIndex )
7563
7584
return -1 ;
0 commit comments