For large values of sb_max or MCLBYTES, it was possible for the expression
sb_max * MCLBYTES / (MSIZE + MCLBYTES) used in sbreserve() to overflow, causing all socket creation attempts to fail. Force the calculation to use u_quad_t's, which makes overflow less likely.
This commit is contained in:
parent
8c21e889fd
commit
5bee01c83f
@ -405,8 +405,7 @@ sbreserve(sb, cc)
|
||||
struct sockbuf *sb;
|
||||
u_long cc;
|
||||
{
|
||||
|
||||
if (cc > sb_max * MCLBYTES / (MSIZE + MCLBYTES))
|
||||
if ((u_quad_t)cc > (u_quad_t)sb_max * MCLBYTES / (MSIZE + MCLBYTES))
|
||||
return (0);
|
||||
sb->sb_hiwat = cc;
|
||||
sb->sb_mbmax = min(cc * sb_efficiency, sb_max);
|
||||
|
@ -405,8 +405,7 @@ sbreserve(sb, cc)
|
||||
struct sockbuf *sb;
|
||||
u_long cc;
|
||||
{
|
||||
|
||||
if (cc > sb_max * MCLBYTES / (MSIZE + MCLBYTES))
|
||||
if ((u_quad_t)cc > (u_quad_t)sb_max * MCLBYTES / (MSIZE + MCLBYTES))
|
||||
return (0);
|
||||
sb->sb_hiwat = cc;
|
||||
sb->sb_mbmax = min(cc * sb_efficiency, sb_max);
|
||||
|
Loading…
Reference in New Issue
Block a user