From b2aa7576a64fe93b591ed4e7b4c811976cf90d11 Mon Sep 17 00:00:00 2001 From: Tinny Ng <tng@apache.org> Date: Thu, 14 Nov 2002 22:16:04 +0000 Subject: [PATCH] [Bug 14479] XMLString::subString failure when len(source)==0 git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@174359 13f79535-47bb-0310-9956-ffa450edef68 --- src/xercesc/util/XMLString.cpp | 35 +++++++++++++++------------------- src/xercesc/util/XMLUri.cpp | 8 ++++++++ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/xercesc/util/XMLString.cpp b/src/xercesc/util/XMLString.cpp index cc87784ce..82a3d1c08 100644 --- a/src/xercesc/util/XMLString.cpp +++ b/src/xercesc/util/XMLString.cpp @@ -592,25 +592,21 @@ void XMLString::trim(char* const toTrim) void XMLString::subString(char* const targetStr, const char* const srcStr , const int startIndex, const int endIndex) { - //if (startIndex < 0 || endIndex < 0) - // ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Str_NegativeIndex); - - if (targetStr == 0) + if (targetStr == 0) ThrowXML(IllegalArgumentException, XMLExcepts::Str_ZeroSizedTargetBuf); const int srcLen = strlen(srcStr); - const int copySize = endIndex - startIndex; + const int copySize = endIndex - startIndex; // Make sure the start index is within the XMLString bounds - if (startIndex > srcLen-1 || endIndex > srcLen ) + if ( startIndex < 0 || startIndex > endIndex || endIndex > srcLen) ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Str_StartIndexPastEnd); - for (int i= startIndex; i < endIndex; i++) { - - targetStr[i-startIndex] = srcStr[i]; - } + for (int i= startIndex; i < endIndex; i++) { + targetStr[i-startIndex] = srcStr[i]; + } - targetStr[copySize] = 0; + targetStr[copySize] = 0; } /** @@ -1450,25 +1446,24 @@ void XMLString::lowerCase(XMLCh* const toLowerCase) void XMLString::subString(XMLCh* const targetStr, const XMLCh* const srcStr , const int startIndex, const int endIndex) { - //if (startIndex < 0 || endIndex < 0) + //if (startIndex < 0 || endIndex < 0) // ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Str_NegativeIndex); - if (targetStr == 0) + if (targetStr == 0) ThrowXML(IllegalArgumentException, XMLExcepts::Str_ZeroSizedTargetBuf); const int srcLen = stringLen(srcStr); - const int copySize = endIndex - startIndex; + const int copySize = endIndex - startIndex; // Make sure the start index is within the XMLString bounds - if (startIndex > srcLen-1 || endIndex > srcLen ) + if ( startIndex < 0 || startIndex > endIndex || endIndex > srcLen) ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Str_StartIndexPastEnd); - for (int i= startIndex; i < endIndex; i++) { - - targetStr[i-startIndex] = srcStr[i]; - } + for (int i= startIndex; i < endIndex; i++) { + targetStr[i-startIndex] = srcStr[i]; + } - targetStr[copySize] = 0; + targetStr[copySize] = 0; } RefVectorOf<XMLCh>* XMLString::tokenizeString(const XMLCh* const tokenizeSrc) diff --git a/src/xercesc/util/XMLUri.cpp b/src/xercesc/util/XMLUri.cpp index ec71810c1..196674bbc 100644 --- a/src/xercesc/util/XMLUri.cpp +++ b/src/xercesc/util/XMLUri.cpp @@ -376,6 +376,14 @@ void XMLUri::initialize(const XMLUri* const baseURI index = XMLString::stringLen(fScheme)+1; } + // It's an error if we stop here + if (index == trimedUriSpecLen) + { + ThrowXML1(NumberFormatException + , XMLExcepts::XMLNUM_URI_Component_Empty + , errMsg_PATH); + } + // two slashes means generic URI syntax, so we get the authority XMLCh* authUriSpec = new XMLCh[trimedUriSpecLen+1]; ArrayJanitor<XMLCh> authName(authUriSpec); -- GitLab