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 15:11:16 +03:00 committed by Andy Green
parent 3cbeef5d26
commit ed79eedb47

View file

@ -27,8 +27,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