Package: libcurl3 Version: 7.22.0-3 Tags: patch curl_easy_reset() does not reset the value of CURLINFO_CONDITION_UNMET returned by curl_easy_getinfo(), therefore if a request sets this flag, it will be never reset to 0 for subsequent requests.
See attached testcase. You can run it with e.g. ./testcurl http://ftp.debian.org/debian/dists/testing/Release.gpg The first request will set a timestamp in the future and condition_unmet will be 1. In the second request the timestamp is in the past, and curl_condition_unmet should be 0, but it is actually 1. The attached patched fixes the bug. I am experiencing the bug on version 7.22, but the latest upstream looks still affected. Cheers, Ludovico
#include <stdio.h> #include <curl/curl.h> #include <stdlib.h> size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) { fprintf(stderr, "Got %zu bytes\n", size*nmemb); return size*nmemb; } void f(CURL* curl, char *argv[], const char* ts) { curl_easy_setopt(curl, CURLOPT_URL, argv[1]); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); if (ts) { long t = atol(ts); fprintf(stderr, "Setting time condition to %ld\n", t); curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE); curl_easy_setopt(curl, CURLOPT_TIMEVALUE, t); } fprintf(stderr, "Performing\n"); CURLcode success = curl_easy_perform(curl); long curl_responsecode; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &curl_responsecode); long curl_condition_unmet = 0; curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &curl_condition_unmet); fprintf(stderr, "Actual: success %d curl_responsecode %ld curl_condition_unmet %ld\n", success, curl_responsecode, curl_condition_unmet); } int main(int argc, char *argv[]) { CURL* curl = curl_easy_init(); fprintf(stderr, "Expect: success 0 curl_responsecode 200 curl_condition_unmet 1\n"); f(curl, argv, "1566210680"); curl_easy_reset(curl); fprintf(stderr, "===\n"); fprintf(stderr, "Expect: success 0 curl_responsecode 200 curl_condition_unmet 0\n"); f(curl, argv, "100000000"); return 0; }
curl-reset-timecond.patch
Description: Binary data