Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-1871

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.0.2, 3.1.0
    • Utilities
    • None
    • FreeBSD 6.2

    Description

      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

      Attachments

        Activity

          People

            bsk Boris Kolpackov
            rucong.zhao rucong zhao
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: