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:
parent
3cbeef5d26
commit
ed79eedb47
1 changed files with 14 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue