size_t conns_in_pool)
{
struct Curl_easy *data = cshutdn->multi->admin;
- size_t max_total = (cshutdn->multi->max_total_connections > 0) ?
- (size_t)cshutdn->multi->max_total_connections : 0;
+ size_t max_total = cshutdn->multi->max_total_connections;
/* Add the connection to our shutdown list for non-blocking shutdown
* during multi processing. */
#endif
#endif
+#if SIZEOF_LONG > SIZEOF_SIZE_T
+#error "unexpected: 'long' is larger than 'size_t'"
+#endif
/*
* Arg 2 type for gethostname in case it has not been defined in config file.
*/
return TRUE;
}
+
+bool curlx_sltouz(long slnum, size_t *puznum)
+{
+ if(slnum < 0) {
+ *puznum = 0;
+ return FALSE;
+ }
+ /* We error in curl_setup.h if SIZEOF_LONG > SIZEOF_SIZE_T */
+ *puznum = (size_t)slnum;
+ return TRUE;
+}
+
curl_off_t curlx_uztoso(size_t uznum)
{
#if SIZEOF_SIZE_T >= SIZEOF_CURL_OFF_T
* too large and set 0 */
bool curlx_sotouz_fits(curl_off_t sonum, size_t *puznum);
+/* Convert a long to size_t, return FALSE if negative or too large
+ * and set 0 */
+bool curlx_sltouz(long sznum, size_t *puznum);
+
#ifdef _WIN32
#undef read
#define read(fd, buf, count) (ssize_t)_read(fd, buf, curlx_uztoui(count))
multi->maxconnects = (unsigned int)uarg;
break;
case CURLMOPT_MAX_HOST_CONNECTIONS:
- multi->max_host_connections = va_arg(param, long);
+ if(!curlx_sltouz(va_arg(param, long), &multi->max_host_connections))
+ res = CURLM_BAD_FUNCTION_ARGUMENT;
break;
case CURLMOPT_MAX_TOTAL_CONNECTIONS:
- multi->max_total_connections = va_arg(param, long);
+ if(!curlx_sltouz(va_arg(param, long), &multi->max_total_connections))
+ res = CURLM_BAD_FUNCTION_ARGUMENT;
break;
/* options formerly used for pipelining */
case CURLMOPT_MAX_PIPELINE_LENGTH:
struct cshutdn cshutdn; /* connection shutdown handling */
struct cpool cpool; /* connection pool (bundles) */
- long max_host_connections; /* if >0, a fixed limit of the maximum number
- of connections per host */
-
- long max_total_connections; /* if >0, a fixed limit of the maximum number
- of connections in total */
+ size_t max_host_connections; /* if >0, a fixed limit of the maximum number
+ of connections per host */
+ size_t max_total_connections; /* if >0, a fixed limit of the maximum number
+ of connections in total */
/* timer callback and user data pointer for the *socket() API */
curl_multi_timer_callback timer_cb;
CURL_TRC_M(data, "Allowing sub-requests (like DoH) to override "
"max connection limit");
else {
- infof(data, "No connections available, total of %ld reached.",
+ infof(data, "No connections available, total of %zu reached.",
data->multi->max_total_connections);
connections_available = FALSE;
}