mirror of
https://github.com/moparisthebest/curl
synced 2024-08-13 17:03:50 -04:00
select: fix overflow protection in Curl_socket_check
Follow-up to a96c752
which changed the timeout_ms type from time_t to
timediff_t.
Ref: https://github.com/curl/curl/pull/5240
Closes https://github.com/curl/curl/pull/5286
This commit is contained in:
parent
0e058776c0
commit
85eda4e87a
13
lib/select.c
13
lib/select.c
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "curl_setup.h"
|
#include "curl_setup.h"
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#ifdef HAVE_SYS_SELECT_H
|
#ifdef HAVE_SYS_SELECT_H
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#elif defined(HAVE_UNISTD_H)
|
#elif defined(HAVE_UNISTD_H)
|
||||||
@ -50,6 +52,7 @@
|
|||||||
#include "urldata.h"
|
#include "urldata.h"
|
||||||
#include "connect.h"
|
#include "connect.h"
|
||||||
#include "select.h"
|
#include "select.h"
|
||||||
|
#include "timeval.h"
|
||||||
#include "warnless.h"
|
#include "warnless.h"
|
||||||
|
|
||||||
/* Convenience local macros */
|
/* Convenience local macros */
|
||||||
@ -216,11 +219,15 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
|
|||||||
int r;
|
int r;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#if SIZEOF_TIME_T != SIZEOF_INT
|
/* prevent overflow. timeout_ms is typecast to time_t and int. */
|
||||||
/* wrap-around precaution */
|
#if TIMEDIFF_T_MAX > INT_MAX
|
||||||
if(timeout_ms >= INT_MAX)
|
if(timeout_ms > INT_MAX)
|
||||||
timeout_ms = INT_MAX;
|
timeout_ms = INT_MAX;
|
||||||
#endif
|
#endif
|
||||||
|
#if INT_MAX > TIME_T_MAX
|
||||||
|
if(timeout_ms > (int)TIME_T_MAX)
|
||||||
|
timeout_ms = (int)TIME_T_MAX;
|
||||||
|
#endif
|
||||||
|
|
||||||
if((readfd0 == CURL_SOCKET_BAD) && (readfd1 == CURL_SOCKET_BAD) &&
|
if((readfd0 == CURL_SOCKET_BAD) && (readfd1 == CURL_SOCKET_BAD) &&
|
||||||
(writefd == CURL_SOCKET_BAD)) {
|
(writefd == CURL_SOCKET_BAD)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user