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

CurlURLInputStream misusing fd_set structure in libcurl and select calls

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.0
    • 3.0.0
    • Miscellaneous
    • None
    • Windows XP, Visual Studio 2005, libcurl 7.17.1

    Description

      I did some work to backport the new libcurl NetAccessor to plugin to Xerces 2.8.0, and found some bugs in the process that are also broken for 3.0. The use of fd_set seems to be broken. Arrays of fd_sets (which are themselves length-prefixed arrays of sockets) are being passed into curl_multi_fdset without being zeroed out with FD_ZERO first, which causes a crash because the socket count on input is wrong.

      I believe the correct code should be to declare only a single set of fd_set variables, not arrays, and call FD_ZERO first, then pass the address of the variables into curl_multi_fdset and the select call below.

      This seems to work for me under simple test cases.

      Specifically the loop at the end looks like:

      // 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 (!tryAgain && fBytesRead == 0)

      { fd_set readSet; fd_set writeSet; fd_set exceptSet; int fdcnt=0; // Ask curl for the file descriptors to wait on FD_ZERO(&readSet); FD_ZERO(&writeSet); FD_ZERO(&exceptSet); (void) curl_multi_fdset(fMulti, &readSet, &writeSet, &exceptSet, &fdcnt); // Wait on the file descriptors timeval tv; tv.tv_sec = 2; tv.tv_usec = 0; (void) select(fdcnt, &readSet, &writeSet, &exceptSet, &tv); }

      A better implementation of this would be to dump the multi libcurl API, which is far more complicated than this use case requires, but I didn't have time to try that for now.

      Attachments

        Activity

          People

            amassari Alberto Massari
            scantor Scott Cantor
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: