Author: borisk
Date: Wed Apr 21 14:20:51 2010
New Revision: 936317

URL: http://svn.apache.org/viewvc?rev=936317&view=rev
Log:
Check that we have non-NULL host before trying to connect (XERCESC-1920).

Modified:
    xerces/c/trunk/src/xercesc/util/NetAccessors/Curl/CurlURLInputStream.cpp
    
xerces/c/trunk/src/xercesc/util/NetAccessors/MacOSURLAccessCF/URLAccessCFBinInputStream.cpp
    
xerces/c/trunk/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp
    
xerces/c/trunk/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp

Modified: 
xerces/c/trunk/src/xercesc/util/NetAccessors/Curl/CurlURLInputStream.cpp
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/NetAccessors/Curl/CurlURLInputStream.cpp?rev=936317&r1=936316&r2=936317&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/NetAccessors/Curl/CurlURLInputStream.cpp 
(original)
+++ xerces/c/trunk/src/xercesc/util/NetAccessors/Curl/CurlURLInputStream.cpp 
Wed Apr 21 14:20:51 2010
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -71,10 +71,10 @@ CurlURLInputStream::CurlURLInputStream(c
 {
        // Allocate the curl multi handle
        fMulti = curl_multi_init();
-       
+
        // Allocate the curl easy handle
        fEasy = curl_easy_init();
-       
+
        // Set URL option
     TranscodeToStr url(fURLSource.getURLText(), "ISO8859-1", fMemoryManager);
        curl_easy_setopt(fEasy, CURLOPT_URL, (char*)url.str());
@@ -82,7 +82,7 @@ CurlURLInputStream::CurlURLInputStream(c
     // Set up a way to recieve the data
        curl_easy_setopt(fEasy, CURLOPT_WRITEDATA, this);                       
                        // Pass this pointer to write function
        curl_easy_setopt(fEasy, CURLOPT_WRITEFUNCTION, staticWriteCallback);    
// Our static write function
-       
+
        // Do redirects
        curl_easy_setopt(fEasy, CURLOPT_FOLLOWLOCATION, (long)1);
        curl_easy_setopt(fEasy, CURLOPT_MAXREDIRS, (long)6);
@@ -178,10 +178,10 @@ CurlURLInputStream::~CurlURLInputStream(
 {
        // Remove the easy handle from the multi stack
        curl_multi_remove_handle(fMulti, fEasy);
-       
+
        // Cleanup the easy handle
        curl_easy_cleanup(fEasy);
-       
+
        // Cleanup the multi handle
        curl_multi_cleanup(fMulti);
 
@@ -214,7 +214,7 @@ CurlURLInputStream::writeCallback(char *
 {
        XMLSize_t cnt = size * nitems;
        XMLSize_t totalConsumed = 0;
-               
+
        // Consume as many bytes as possible immediately into the buffer
        XMLSize_t consume = (cnt > fBytesToRead) ? fBytesToRead : cnt;
        memcpy(fWritePtr, buffer, consume);
@@ -239,7 +239,7 @@ CurlURLInputStream::writeCallback(char *
                totalConsumed   += consume;
                //printf("write callback rebuffering %d bytes\n", consume);
        }
-       
+
        // Return the total amount we've consumed. If we don't consume all the 
bytes
        // then an error will be generated. Since our buffer size is equal to 
the
        // maximum size that curl will write, this should never happen unless 
there
@@ -267,7 +267,7 @@ bool CurlURLInputStream::readMore(int *r
 {
     // Ask the curl to do some work
     CURLMcode curlResult = curl_multi_perform(fMulti, runningHandles);
-               
+
     // Process messages from curl
     int msgsInQueue = 0;
     for (CURLMsg* msg = NULL; (msg = curl_multi_info_read(fMulti, 
&msgsInQueue)) != NULL; )
@@ -276,26 +276,31 @@ bool CurlURLInputStream::readMore(int *r
 
         if (msg->msg != CURLMSG_DONE)
             return true;
-                               
+
         switch (msg->data.result)
         {
         case CURLE_OK:
             // We completed successfully. runningHandles should have dropped 
to zero, so we'll bail out below...
             break;
-                               
+
         case CURLE_UNSUPPORTED_PROTOCOL:
             ThrowXMLwithMemMgr(MalformedURLException, 
XMLExcepts::URL_UnsupportedProto, fMemoryManager);
             break;
 
         case CURLE_COULDNT_RESOLVE_HOST:
         case CURLE_COULDNT_RESOLVE_PROXY:
-            ThrowXMLwithMemMgr1(NetAccessorException,  
XMLExcepts::NetAcc_TargetResolution, fURLSource.getHost(), fMemoryManager);
+          {
+            if (fURLSource.getHost())
+              ThrowXMLwithMemMgr1(NetAccessorException, 
XMLExcepts::NetAcc_TargetResolution, fURLSource.getHost(), fMemoryManager);
+            else
+              ThrowXMLwithMemMgr1(NetAccessorException, 
XMLExcepts::File_CouldNotOpenFile, fURLSource.getURLText(), fMemoryManager);
             break;
-                
+          }
+
         case CURLE_COULDNT_CONNECT:
             ThrowXMLwithMemMgr1(NetAccessorException, 
XMLExcepts::NetAcc_ConnSocket, fURLSource.getURLText(), fMemoryManager);
             break;
-               
+
         case CURLE_RECV_ERROR:
             ThrowXMLwithMemMgr1(NetAccessorException, 
XMLExcepts::NetAcc_ReadSocket, fURLSource.getURLText(), fMemoryManager);
             break;
@@ -309,7 +314,7 @@ bool CurlURLInputStream::readMore(int *r
     // If nothing is running any longer, bail out
     if(*runningHandles == 0)
         return false;
-               
+
     // If there is no further data to read, and we haven't
     // read any yet on this invocation, call select to wait for data
     if (curlResult != CURLM_CALL_MULTI_PERFORM && fBytesRead == 0)
@@ -343,7 +348,7 @@ CurlURLInputStream::readBytes(XMLByte* c
        fBytesRead = 0;
        fBytesToRead = maxToRead;
        fWritePtr = toFill;
-       
+
        for (bool tryAgain = true; fBytesToRead > 0 && (tryAgain || fBytesRead 
== 0); )
        {
                // First, any buffered data we have available
@@ -356,21 +361,21 @@ CurlURLInputStream::readBytes(XMLByte* c
                        fBytesRead              += bufCnt;
                        fTotalBytesRead += bufCnt;
                        fBytesToRead    -= bufCnt;
-                       
+
                        fBufferTailPtr  += bufCnt;
                        if (fBufferTailPtr == fBufferHeadPtr)
                                fBufferHeadPtr = fBufferTailPtr = fBuffer;
-                               
+
                        //printf("consuming %d buffered bytes\n", bufCnt);
 
                        tryAgain = true;
                        continue;
                }
-       
+
                // Ask the curl to do some work
                int runningHandles = 0;
         tryAgain = readMore(&runningHandles);
-               
+
                // If nothing is running any longer, bail out
                if (runningHandles == 0)
                        break;
@@ -385,4 +390,3 @@ const XMLCh *CurlURLInputStream::getCont
 }
 
 XERCES_CPP_NAMESPACE_END
-

Modified: 
xerces/c/trunk/src/xercesc/util/NetAccessors/MacOSURLAccessCF/URLAccessCFBinInputStream.cpp
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/NetAccessors/MacOSURLAccessCF/URLAccessCFBinInputStream.cpp?rev=936317&r1=936316&r2=936317&view=diff
==============================================================================
--- 
xerces/c/trunk/src/xercesc/util/NetAccessors/MacOSURLAccessCF/URLAccessCFBinInputStream.cpp
 (original)
+++ 
xerces/c/trunk/src/xercesc/util/NetAccessors/MacOSURLAccessCF/URLAccessCFBinInputStream.cpp
 Wed Apr 21 14:20:51 2010
@@ -100,8 +100,13 @@ URLAccessCFBinInputStream::URLAccessCFBi
                 break;
 
             case kCFURLRemoteHostUnavailableError:
-                ThrowXML1(NetAccessorException,  
XMLExcepts::NetAcc_TargetResolution, urlSource.getHost());
+              {
+                if (urlSource.getHost())
+                  ThrowXML1(NetAccessorException, 
XMLExcepts::NetAcc_TargetResolution, urlSource.getHost());
+                else
+                  ThrowXML1(NetAccessorException, 
XMLExcepts::File_CouldNotOpenFile, urlText);
                 break;
+              }
 
             case kCFURLUnknownError:
                 ThrowXML1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, 
urlText);

Modified: 
xerces/c/trunk/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp?rev=936317&r1=936316&r2=936317&view=diff
==============================================================================
--- 
xerces/c/trunk/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp 
(original)
+++ 
xerces/c/trunk/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp 
Wed Apr 21 14:20:51 2010
@@ -104,6 +104,13 @@ UnixHTTPURLInputStream::UnixHTTPURLInput
     MemoryManager *memoryManager = urlSource.getMemoryManager();
 
     const XMLCh*        hostName = urlSource.getHost();
+
+    if (hostName == 0)
+      ThrowXMLwithMemMgr1(NetAccessorException,
+                          XMLExcepts::File_CouldNotOpenFile,
+                          urlSource.getURLText(),
+                          memoryManager);
+
     char*               hostNameAsCharStar = XMLString::transcode(hostName, 
memoryManager);
     ArrayJanitor<char>  janHostNameAsCharStar(hostNameAsCharStar, 
memoryManager);
 
@@ -217,9 +224,16 @@ UnixHTTPURLInputStream::UnixHTTPURLInput
             }
 
             url = newURL;
+            hostName = newURL.getHost();
+
+            if (hostName == 0)
+              ThrowXMLwithMemMgr1(NetAccessorException,
+                                  XMLExcepts::File_CouldNotOpenFile,
+                                  newURL.getURLText(),
+                                  memoryManager);
 
             janHostNameAsCharStar.release();
-            hostNameAsCharStar = XMLString::transcode(newURL.getHost(), 
memoryManager);
+            hostNameAsCharStar = XMLString::transcode(hostName, memoryManager);
             janHostNameAsCharStar.reset(hostNameAsCharStar, memoryManager);
         }
         else {

Modified: 
xerces/c/trunk/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp?rev=936317&r1=936316&r2=936317&view=diff
==============================================================================
--- 
xerces/c/trunk/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp 
(original)
+++ 
xerces/c/trunk/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp 
Wed Apr 21 14:20:51 2010
@@ -312,6 +312,13 @@ BinHTTPURLInputStream::BinHTTPURLInputSt
     //   and transcode them back to ASCII.
     //
     const XMLCh*        hostName = urlSource.getHost();
+
+    if (hostName == 0)
+      ThrowXMLwithMemMgr1(NetAccessorException,
+                          XMLExcepts::File_CouldNotOpenFile,
+                          urlSource.getURLText(),
+                          memoryManager);
+
     char*               hostNameAsCharStar = XMLString::transcode(hostName, 
memoryManager);
     ArrayJanitor<char>  janHostNameAsCharStar(hostNameAsCharStar, 
memoryManager);
 
@@ -437,9 +444,16 @@ BinHTTPURLInputStream::BinHTTPURLInputSt
             }
 
             url = newURL;
+            hostName = newURL.getHost();
+
+            if (hostName == 0)
+              ThrowXMLwithMemMgr1(NetAccessorException,
+                                  XMLExcepts::File_CouldNotOpenFile,
+                                  newURL.getURLText(),
+                                  memoryManager);
 
             janHostNameAsCharStar.release();
-            hostNameAsCharStar = XMLString::transcode(newURL.getHost(), 
memoryManager);
+            hostNameAsCharStar = XMLString::transcode(hostName, memoryManager);
             janHostNameAsCharStar.reset(hostNameAsCharStar, memoryManager);
         }
         else {



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to