diff --git a/common/optparser.c b/common/optparser.c index 3e9c7fe13..8d02de651 100644 --- a/common/optparser.c +++ b/common/optparser.c @@ -555,7 +555,7 @@ const struct clam_option __clam_options[] = { {"ConnectTimeout", NULL, 0, CLOPT_TYPE_NUMBER, MATCH_NUMBER, 30, NULL, 0, OPT_FRESHCLAM, "Timeout in seconds when connecting to database server.", "30"}, - {"ReceiveTimeout", NULL, 0, CLOPT_TYPE_NUMBER, MATCH_NUMBER, 0, NULL, 0, OPT_FRESHCLAM, "Maximum time in seconds for each download operation. 0 means no timeout.", "0"}, + {"ReceiveTimeout", NULL, 0, CLOPT_TYPE_NUMBER, MATCH_NUMBER, 60, NULL, 0, OPT_FRESHCLAM, "Timeout in seconds when reading from database server. 0 means no timeout.", "60"}, {"Bytecode", NULL, 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 1, NULL, 0, OPT_FRESHCLAM, "This option enables downloading of bytecode.cvd, which includes additional\ndetection mechanisms and improvements to the ClamAV engine.", "yes"}, diff --git a/etc/freshclam.conf.sample b/etc/freshclam.conf.sample index 0330c056c..26c4e7a63 100644 --- a/etc/freshclam.conf.sample +++ b/etc/freshclam.conf.sample @@ -175,9 +175,9 @@ DatabaseMirror database.clamav.net # Default: 30 #ConnectTimeout 60 -# Maximum time in seconds for each download operation. 0 means no timeout. -# Default: 0 -#ReceiveTimeout 1800 +# Timeout in seconds when reading from database server. 0 means no timeout. +# Default: 60 +#ReceiveTimeout 300 # With this option enabled, freshclam will attempt to load new databases into # memory to make sure they are properly handled by libclamav before replacing diff --git a/libfreshclam/libfreshclam.h b/libfreshclam/libfreshclam.h index 6782c1018..f3d1e04b6 100644 --- a/libfreshclam/libfreshclam.h +++ b/libfreshclam/libfreshclam.h @@ -48,7 +48,7 @@ typedef struct fc_config_ { uint64_t maxLogSize; /**< Max size of logfile, if enabled. */ uint32_t maxAttempts; /**< Max # of download attempts. Must be > 0 */ uint32_t connectTimeout; /**< CURLOPT_CONNECTTIMEOUT, Timeout for the. connection phase (seconds). */ - uint32_t requestTimeout; /**< CURLOPT_TIMEOUT, Timeout for libcurl transfer operation (seconds). */ + uint32_t requestTimeout; /**< CURLOPT_LOW_SPEED_TIME, Timeout for libcurl transfer operation (seconds). */ uint32_t bCompressLocalDatabase; /**< If set, will apply gz compression to CLD databases. */ const char *logFile; /**< (optional) Filepath to use for log output, if desired. */ const char *logFacility; /**< (optional) System logging facility (I.e. "syslog"), if desired. */ diff --git a/libfreshclam/libfreshclam_internal.c b/libfreshclam/libfreshclam_internal.c index f3cf0d5fc..f7c5ccd71 100644 --- a/libfreshclam/libfreshclam_internal.c +++ b/libfreshclam/libfreshclam_internal.c @@ -623,8 +623,16 @@ static fc_error_t create_curl_handle( if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, g_connectTimeout)) { logg("!create_curl_handle: Failed to set CURLOPT_CONNECTTIMEOUT (%u)!\n", g_connectTimeout); } - if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_TIMEOUT, g_requestTimeout)) { - logg("!create_curl_handle: Failed to set CURLOPT_TIMEOUT (%u)!\n", g_requestTimeout); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, g_requestTimeout)) { + logg("!create_curl_handle: Failed to set CURLOPT_LOW_SPEED_TIME (%u)!\n", g_requestTimeout); + } + if (g_requestTimeout > 0) { + /* Minimum speed is 1 byte/second over the previous g_requestTimeout seconds. */ + int minimumSpeed = 1; + + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, minimumSpeed)) { + logg("!create_curl_handle: Failed to set CURLOPT_LOW_SPEED_LIMIT (%u)!\n", minimumSpeed); + } } if (bAllowRedirect) { diff --git a/win32/conf_examples/freshclam.conf.sample b/win32/conf_examples/freshclam.conf.sample index 8e62bf3e3..7e97ee30e 100644 --- a/win32/conf_examples/freshclam.conf.sample +++ b/win32/conf_examples/freshclam.conf.sample @@ -172,9 +172,9 @@ DatabaseMirror database.clamav.net # Default: 30 #ConnectTimeout 60 -# Maximum time in seconds for each download operation. 0 means no timeout. -# Default: 0 -#ReceiveTimeout 1800 +# Timeout in seconds when reading from database server. 0 means no timeout. +# Default: 60 +#ReceiveTimeout 300 # With this option enabled, freshclam will attempt to load new databases into # memory to make sure they are properly handled by libclamav before replacing