libs3 icon indicating copy to clipboard operation
libs3 copied to clipboard

request_headers_done doesn't check for request->status when calling the properties callback

Open alex-zadara opened this issue 9 years ago • 0 comments

It may happen that when we enter this function, we already have request->status != S3StatusOk. Then we call curl_easy_getinfo(CURLINFO_RESPONSE_CODE) and we receive httpResponseCode=200. As a result, we will call the properties callback, due to this code:

    // Only make the callback if it was a successful request; otherwise we're
    // returning information about the error response itself
    if (request->propertiesCallback &&
        (request->httpResponseCode >= 200) &&
        (request->httpResponseCode <= 299)) {
        request->status = (*(request->propertiesCallback))
            (&(request->responseHeadersHandler.responseProperties), 
             request->callbackData);
    }

This code doesn't check request->status. The properties callback returns S3StatusOk, and we kill the original request->status value. As a result, caller thinks request succeeded, but it really failed.

The following simple fix works:

    // Only make the callback if it was a successful request; otherwise we're
    // returning information about the error response itself
    if (request->propertiesCallback &&
        // Also check request->status
        request->status == S3StatusOK &&
        (request->httpResponseCode >= 200) &&
        (request->httpResponseCode <= 299)) {
        request->status = (*(request->propertiesCallback))
            (&(request->responseHeadersHandler.responseProperties), 
             request->callbackData);
    }

alex-zadara avatar Mar 08 '15 16:03 alex-zadara