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:
Garrett Wollman 1997-02-13 18:05:46 +00:00
parent 8c21e889fd
commit 5bee01c83f
2 changed files with 2 additions and 4 deletions

View File

@ -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);

View File

@ -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);