1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

sul_compare: prevent integer overflow bug

This commit is contained in:
Sviatoslav Grebenchucov 2019-08-25 19:52:11 +01:00 committed by Andy Green
parent d9dd253021
commit 550023ce78

View file

@ -24,8 +24,20 @@
static int
sul_compare(const lws_dll2_t *d, const lws_dll2_t *i)
{
return ((lws_sorted_usec_list_t *)d)->us -
((lws_sorted_usec_list_t *)i)->us;
lws_usec_t a = ((lws_sorted_usec_list_t *)d)->us;
lws_usec_t b = ((lws_sorted_usec_list_t *)i)->us;
/*
* Simply returning (a - b) in an int
* may lead to an integer overflow bug
*/
if (a > b)
return 1;
if (a < b)
return -1;
return 0;
}
int