getaddrinfo() hits Segmentation fault on FreeBSD when accessing remote data.
----------------------------------------------------------------------------

                 Key: XERCESC-1871
                 URL: https://issues.apache.org/jira/browse/XERCESC-1871
             Project: Xerces-C++
          Issue Type: Bug
          Components: Utilities
         Environment: FreeBSD 6.2
            Reporter: rucong zhao
            Priority: Minor


Hi,

When accessing remote data, my program hits Segmentation fault. I've debug the 
issue and make sure that the cause is using "if (n<0)" to judge the getaddrinfo 
errors. In fact we should use "if (n!=0)" according to getaddrinfo() standard.

In the file: 
xercesc/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp, line 
127:
   int n = getaddrinfo(hostNameAsCharStar,portBuffer.getRawBuffer(),&hints, 
&res);
   if(n<0)
   {
       hints.ai_flags = AI_NUMERICHOST;
       n = getaddrinfo(hostNameAsCharStar,portBuffer.getRawBuffer(),&hints, 
&res);
       if(n<0)
           ThrowXMLwithMemMgr1(NetAccessorException, 
XMLExcepts::NetAcc_TargetResolution, hostName, memoryManager);
   }


http://linux.die.net/man/3/getaddrinfo point out that "getaddrinfo(3) returns 0 
if it succeeds, or one of the following non-zero error codes". So the error 
code is not negative in all platform.

I've wrote a test program and run in both Linux and FreeBSD. The result show 
that the error codes on FreeBSD are positive number:
Linux:
   error in getaddrinfo: Name or service not known
   error code: -2
FreeBSD:
   error in getaddrinfo: hostname nor servname provided, or not known
   error code: 8

So the fix should be changing upon two "if(n<0)" into "if(n!=0)". The fix works 
on my machine.

Thanks,
Rucong 


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Reply via email to