[MacPorts] #60581: garbage error output from failed curl

MacPorts noreply at macports.org
Fri Jun 12 07:16:28 UTC 2020


#60581: garbage error output from failed curl
-------------------------+--------------------
  Reporter:  ryandesign  |      Owner:  (none)
      Type:  defect      |     Status:  new
  Priority:  Normal      |  Milestone:
 Component:  base        |    Version:  2.6.2
Resolution:              |   Keywords:
      Port:              |
-------------------------+--------------------
Changes (by ryandesign):

 * cc: neverpanic (added)


Comment:

 Looking through the code in CurlFetchCmd in src/pextlib1.0/curl.c, I see
 this:

 {{{
         char theErrorString[CURL_ERROR_SIZE];
 }}}
 {{{
                 theCurlCode = curl_easy_setopt(theHandle,
 CURLOPT_ERRORBUFFER, theErrorString);
                 if (theCurlCode != CURLE_OK) {
                         theResult = SetResultFromCurlErrorCode(interp,
 theCurlCode);
                         break;
                 }
 }}}

 This tells curl to fill theErrorString with an error message if it occurs.

 We later use that variable like this:

 {{{
                 if (info->data.result != CURLE_OK) {
                         /* execution failed, use the error string */
                         Tcl_SetResult(interp, theErrorString,
 TCL_VOLATILE);
                         theResult = TCL_ERROR;
                         break;
                 }
 }}}

 I think the problem is that curl does not guarantee that it has filled the
 error buffer with anything, even if an error occurred. From
 [https://curl.haxx.se/libcurl/c/CURLOPT_ERRORBUFFER.html the
 documentation]:

 > Pass a char * to a buffer that libcurl '''may''' store human readable
 error messages [in] on failures or problems.
 > [...]
 > Do not rely on the contents of the buffer unless an error code was
 returned. Since 7.60.0 libcurl will initialize the contents of the error
 buffer to an empty string before performing the transfer. For earlier
 versions if an error code was returned but there was no error detail then
 the buffer is untouched.

 I was using High Sierra, whose libcurl version if 7.54.0, which means it
 does not initialize the error buffer to the empty string. It would
 probably be a good idea for us to initialize it to the empty string. And
 later when we want to pass it to Tcl, we might want to check if it is
 still the empty string and if so substitute a generic error message.

-- 
Ticket URL: <https://trac.macports.org/ticket/60581#comment:1>
MacPorts <https://www.macports.org/>
Ports system for macOS


More information about the macports-tickets mailing list