1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
|
Description: CVE-2016-0729: Buffer overlows during processing and error rep orting
Origin: upstream, http://svn.apache.org/viewvc?view=revision&revision=1727978
Forwarded: not-needed
Author: Scott Cantor <cantor.2@osu.edu>
Reviewed-by: Salvatore Bonaccorso <carnil@debian.org>
Last-Update: 2016-02-24
Applied-Upstream: 3.1.3
--- a/src/xercesc/internal/XMLReader.cpp
+++ b/src/xercesc/internal/XMLReader.cpp
@@ -1460,8 +1460,30 @@ void XMLReader::doInitDecode()
while (fRawBufIndex < fRawBytesAvail)
{
- // Security fix: make sure there are at least sizeof(UCS4Ch) bytes to consume.
+ // Make sure there are at least sizeof(UCS4Ch) bytes to co nsume.
if (fRawBufIndex + sizeof(UCS4Ch) > fRawBytesAvail) {
+ fCharsAvail = 0;
+ fRawBufIndex = 0;
+ fMemoryManager->deallocate(fPublicId);
+ fMemoryManager->deallocate(fEncodingStr);
+ ArrayJanitor<XMLCh> janValue(fSystemId, fMemoryManager);
+ ThrowXMLwithMemMgr1
+ (
+ TranscodingException
+ , XMLExcepts::Reader_CouldNotDecodeFirstLine
+ , fSystemId
+ , fMemoryManager
+ );
+ }
+
+ // Make sure we don't exhaust the limited prolog buffer size.
+ // Leave room for a space added at the end of this function.
+ if (fCharsAvail == kCharBufSize - 1) {
+ fCharsAvail = 0;
+ fRawBufIndex = 0;
+ fMemoryManager->deallocate(fPublicId);
+ fMemoryManager->deallocate(fEncodingStr);
+ ArrayJanitor<XMLCh> janValue(fSystemId, fMemoryManager);
ThrowXMLwithMemMgr1
(
TranscodingException
@@ -1547,6 +1569,23 @@ void XMLReader::doInitDecode()
const char curCh = *asChars++;
fRawBufIndex++;
+ // Make sure we don't exhaust the limited prolog buffer size.
+ // Leave room for a space added at the end of this function.
+ if (fCharsAvail == kCharBufSize - 1) {
+ fCharsAvail = 0;
+ fRawBufIndex = 0;
+ fMemoryManager->deallocate(fPublicId);
+ fMemoryManager->deallocate(fEncodingStr);
+ ArrayJanitor<XMLCh> janValue(fSystemId, fMemoryManager);
+ ThrowXMLwithMemMgr1
+ (
+ TranscodingException
+ , XMLExcepts::Reader_CouldNotDecodeFirstLine
+ , fSystemId
+ , fMemoryManager
+ );
+ }
+
// Looks ok, so store it
fCharSizeBuf[fCharsAvail] = 1;
fCharBuf[fCharsAvail++] = XMLCh(curCh);
@@ -1630,8 +1669,30 @@ void XMLReader::doInitDecode()
while (fRawBufIndex < fRawBytesAvail)
{
- // Security fix: make sure there are at least sizeof(UTF16Ch) bytes to consume.
+ // Make sure there are at least sizeof(UTF16Ch) bytes to consume.
if (fRawBufIndex + sizeof(UTF16Ch) > fRawBytesAvail) {
+ fCharsAvail = 0;
+ fRawBufIndex = 0;
+ fMemoryManager->deallocate(fPublicId);
+ fMemoryManager->deallocate(fEncodingStr);
+ ArrayJanitor<XMLCh> janValue(fSystemId, fMemoryManager);
+ ThrowXMLwithMemMgr1
+ (
+ TranscodingException
+ , XMLExcepts::Reader_CouldNotDecodeFirstLine
+ , fSystemId
+ , fMemoryManager
+ );
+ }
+
+ // Make sure we don't exhaust the limited prolog buffer size.
+ // Leave room for a space added at the end of this function.
+ if (fCharsAvail == kCharBufSize - 1) {
+ fCharsAvail = 0;
+ fRawBufIndex = 0;
+ fMemoryManager->deallocate(fPublicId);
+ fMemoryManager->deallocate(fEncodingStr);
+ ArrayJanitor<XMLCh> janValue(fSystemId, fMemoryManager);
ThrowXMLwithMemMgr1
(
TranscodingException
@@ -1676,6 +1737,24 @@ void XMLReader::doInitDecode()
const XMLCh chCur = XMLEBCDICTranscoder::xlatThisOne(*srcPtr++);
fRawBufIndex++;
+ // Make sure we don't exhaust the limited prolog buffer size.
+ // Leave room for a space added at the end of this function.
+ if (fCharsAvail == kCharBufSize - 1) {
+ fCharsAvail = 0;
+ fRawBufIndex = 0;
+ fMemoryManager->deallocate(fPublicId);
+ fMemoryManager->deallocate(fEncodingStr);
+ ArrayJanitor<XMLCh> janValue(fSystemId, fMemoryManager);
+ ThrowXMLwithMemMgr1
+ (
+ TranscodingException
+ , XMLExcepts::Reader_CouldNotDecodeFirstLine
+ , fSystemId
+ , fMemoryManager
+ );
+ }
+
+
//
// And put it into the character buffer. This stuff has to
// look like it was normally transcoded.
@@ -1730,7 +1809,7 @@ void XMLReader::doInitDecode()
//
void XMLReader::refreshRawBuffer()
{
- // Security fix: make sure we don't underflow on the subtraction.
+ // Make sure we don't underflow on the subtraction.
if (fRawBufIndex > fRawBytesAvail) {
ThrowXMLwithMemMgr1
(
--- a/src/xercesc/util/XMLURL.cpp
+++ b/src/xercesc/util/XMLURL.cpp
@@ -611,9 +611,20 @@ BinInputStream* XMLURL::makeNewStream()
while (percentIndex != -1) {
- if (percentIndex+2 >= (int)end ||
- !isHexDigit(realPath[percentIndex+1]) ||
- !isHexDigit(realPath[percentIndex+2]))
+ // Isolate the length/boundary check so we don't try and copy off the end.
+ if (percentIndex+2 >= (int)end)
+ {
+ XMLCh value1[3];
+ value1[1] = chNull;
+ value1[2] = chNull;
+ XMLString::moveChars(value1, &(realPath[percentIndex]), (percentIndex + 1 >= (int)end ? 1 : 2));
+ ThrowXMLwithMemMgr2(MalformedURLException
+ , XMLExcepts::XMLNUM_URI_Component_Invalid_EscapeSequence
+ , realPath
+ , value1
+ , fMemoryManager);
+ }
+ else if (!isHexDigit(realPath[percentIndex+1]) || !isHexDigit(realPath[percentIndex+2]))
{
XMLCh value1[4];
XMLString::moveChars(value1, &(realPath[percentIndex]), 3);
--- a/src/xercesc/util/XMLUri.cpp
+++ b/src/xercesc/util/XMLUri.cpp
@@ -875,11 +875,21 @@ void XMLUri::initializePath(const XMLCh*
// check for valid escape sequence
if (testChar == chPercent)
{
- if (index+2 >= end ||
- !XMLString::isHex(uriSpec[index+1]) ||
- !XMLString::isHex(uriSpec[index+2]))
+ if (index + 2 >= end)
{
- XMLCh value1[BUF_LEN+1];
+ XMLCh value1[3];
+ value1[1] = chNull;
+ value1[2] = chNull;
+ XMLString::moveChars(value1, &(uriSpec[index]), (index + 1 >= end ? 1 : 2));
+ ThrowXMLwithMemMgr2(MalformedURLException
+ , XMLExcepts::XMLNUM_URI_Component_Invalid_EscapeSequence
+ , errMsg_PATH
+ , value1
+ , fMemoryManager);
+ }
+ else if (!XMLString::isHex(uriSpec[index+1]) || !XMLString::isHex(uriSpec[index+2]))
+ {
+ XMLCh value1[4];
XMLString::moveChars(value1, &(uriSpec[index]), 3);
value1[3] = chNull;
ThrowXMLwithMemMgr2(MalformedURLException
@@ -892,7 +902,7 @@ void XMLUri::initializePath(const XMLCh*
else if (!isUnreservedCharacter(testChar) &&
!isPathCharacter(testChar))
{
- XMLCh value1[BUF_LEN+1];
+ XMLCh value1[2];
value1[0] = testChar;
value1[1] = chNull;
ThrowXMLwithMemMgr2(MalformedURLException
@@ -920,11 +930,21 @@ void XMLUri::initializePath(const XMLCh*
// check for valid escape sequence
if (testChar == chPercent)
{
- if (index+2 >= end ||
- !XMLString::isHex(uriSpec[index+1]) ||
- !XMLString::isHex(uriSpec[index+2]))
+ if (index + 2 >= end)
{
- XMLCh value1[BUF_LEN+1];
+ XMLCh value1[3];
+ value1[1] = chNull;
+ value1[2] = chNull;
+ XMLString::moveChars(value1, &(uriSpec[index]), (index + 1 >= end ? 1 : 2));
+ ThrowXMLwithMemMgr2(MalformedURLException
+ , XMLExcepts::XMLNUM_URI_Component_Invalid_EscapeSequence
+ , errMsg_PATH
+ , value1
+ , fMemoryManager);
+ }
+ else if (!XMLString::isHex(uriSpec[index+1]) || !XMLString::isHex(uriSpec[index+2]))
+ {
+ XMLCh value1[4];
XMLString::moveChars(value1, &(uriSpec[index]), 3);
value1[3] = chNull;
ThrowXMLwithMemMgr2(MalformedURLException
@@ -941,7 +961,7 @@ void XMLUri::initializePath(const XMLCh*
// contains '[' and ']'.
else if (!isReservedOrUnreservedCharacter(testChar))
{
- XMLCh value1[BUF_LEN+1];
+ XMLCh value1[2];
value1[0] = testChar;
value1[1] = chNull;
ThrowXMLwithMemMgr2(MalformedURLException
@@ -979,11 +999,21 @@ void XMLUri::initializePath(const XMLCh*
if (testChar == chPercent)
{
- if (index+2 >= end ||
- !XMLString::isHex(uriSpec[index+1]) ||
- !XMLString::isHex(uriSpec[index+2]))
+ if (index + 2 >= end)
+ {
+ XMLCh value1[3];
+ value1[1] = chNull;
+ value1[2] = chNull;
+ XMLString::moveChars(value1, &(uriSpec[index]), (index + 1 >= end ? 1 : 2));
+ ThrowXMLwithMemMgr2(MalformedURLException
+ , XMLExcepts::XMLNUM_URI_Component_Invalid_EscapeSequence
+ , errMsg_QUERY
+ , value1
+ , fMemoryManager);
+ }
+ if (!XMLString::isHex(uriSpec[index+1]) || !XMLString::isHex(uriSpec[index+2]))
{
- XMLCh value1[BUF_LEN+1];
+ XMLCh value1[4];
XMLString::moveChars(value1, &(uriSpec[index]), 3);
value1[3] = chNull;
ThrowXMLwithMemMgr2(MalformedURLException
@@ -995,7 +1025,7 @@ void XMLUri::initializePath(const XMLCh*
}
else if (!isReservedOrUnreservedCharacter(testChar))
{
- XMLCh value1[BUF_LEN+1];
+ XMLCh value1[2];
value1[0] = testChar;
value1[1] = chNull;
ThrowXMLwithMemMgr2(MalformedURLException
@@ -1030,11 +1060,21 @@ void XMLUri::initializePath(const XMLCh*
if (testChar == chPercent)
{
- if (index+2 >= end ||
- !XMLString::isHex(uriSpec[index+1]) ||
- !XMLString::isHex(uriSpec[index+2]))
+ if (index + 2 >= end)
+ {
+ XMLCh value1[3];
+ value1[1] = chNull;
+ value1[2] = chNull;
+ XMLString::moveChars(value1, &(uriSpec[index]), (index + 1 >= end ? 1 : 2));
+ ThrowXMLwithMemMgr2(MalformedURLException
+ , XMLExcepts::XMLNUM_URI_Component_Invalid_EscapeSequence
+ , errMsg_FRAGMENT
+ , value1
+ , fMemoryManager);
+ }
+ if (!XMLString::isHex(uriSpec[index+1]) || !XMLString::isHex(uriSpec[index+2]))
{
- XMLCh value1[BUF_LEN+1];
+ XMLCh value1[4];
XMLString::moveChars(value1, &(uriSpec[index]), 3);
value1[3] = chNull;
ThrowXMLwithMemMgr2(MalformedURLException
@@ -1046,7 +1086,7 @@ void XMLUri::initializePath(const XMLCh*
}
else if (!isReservedOrUnreservedCharacter(testChar))
{
- XMLCh value1[BUF_LEN+1];
+ XMLCh value1[2];
value1[0] = testChar;
value1[1] = chNull;
ThrowXMLwithMemMgr2(MalformedURLException
@@ -1410,14 +1450,15 @@ void XMLUri::isConformantUserInfo(const
}
else if (*tmpStr == chPercent) // '%'
{
- if (XMLString::isHex(*(tmpStr+1)) && // 1st hex
- XMLString::isHex(*(tmpStr+2)) ) // 2nd hex
+ if (XMLString::stringLen(tmpStr) >= 3
+ && XMLString::isHex(*(tmpStr+1)) // 1st hex
+ && XMLString::isHex(*(tmpStr+2)) ) // 2nd hex
{
tmpStr+=3;
}
else
{
- XMLCh value1[BUF_LEN+1];
+ XMLCh value1[4];
value1[0] = chPercent;
value1[1] = *(tmpStr+1);
value1[2] = *(tmpStr+2);
@@ -1468,8 +1509,9 @@ bool XMLUri::isValidServerBasedAuthority
}
else if (userinfo[index] == chPercent) // '%'
{
- if (XMLString::isHex(userinfo[index+1]) && // 1st hex
- XMLString::isHex(userinfo[index+2]) ) // 2nd hex
+ if (index + 2 < userLen
+ && XMLString::isHex(userinfo[index+1]) // 1st hex
+ && XMLString::isHex(userinfo[index+2]) ) // 2nd hex
index +=3;
else
return false;
@@ -1508,8 +1550,9 @@ bool XMLUri::isValidServerBasedAuthority
}
else if (*tmpStr == chPercent) // '%'
{
- if (XMLString::isHex(*(tmpStr+1)) && // 1st hex
- XMLString::isHex(*(tmpStr+2)) ) // 2nd hex
+ if (XMLString::stringLen(tmpStr) >= 3
+ && XMLString::isHex(*(tmpStr+1)) // 1st hex
+ && XMLString::isHex(*(tmpStr+2)) ) // 2nd hex
{
tmpStr+=3;
}
@@ -1537,8 +1580,9 @@ bool XMLUri::isValidRegistryBasedAuthori
}
else if (authority[index] == chPercent) // '%'
{
- if (XMLString::isHex(authority[index+1]) && // 1st hex
- XMLString::isHex(authority[index+2]) ) // 2nd hex
+ if (index + 2 < authLen
+ && XMLString::isHex(authority[index+1]) // 1st hex
+ && XMLString::isHex(authority[index+2]) ) // 2nd hex
index +=3;
else
return false;
@@ -1566,8 +1610,9 @@ bool XMLUri::isValidRegistryBasedAuthori
}
else if (*tmpStr == chPercent) // '%'
{
- if (XMLString::isHex(*(tmpStr+1)) && // 1st hex
- XMLString::isHex(*(tmpStr+2)) ) // 2nd hex
+ if (XMLString::stringLen(tmpStr) >= 3
+ && XMLString::isHex(*(tmpStr + 1)) // 1st hex
+ && XMLString::isHex(*(tmpStr + 2))) // 2nd hex
{
tmpStr+=3;
}
@@ -1602,8 +1647,9 @@ bool XMLUri::isURIString(const XMLCh* co
}
else if (*tmpStr == chPercent) // '%'
{
- if (XMLString::isHex(*(tmpStr+1)) && // 1st hex
- XMLString::isHex(*(tmpStr+2)) ) // 2nd hex
+ if (XMLString::stringLen(tmpStr) >=3
+ && XMLString::isHex(*(tmpStr+1)) // 1st hex
+ && XMLString::isHex(*(tmpStr+2)) ) // 2nd hex
{
tmpStr+=3;
}
|