From 5213c50d83bdbdb7ef30dfc5ea7b2b418459a975 Mon Sep 17 00:00:00 2001 From: Mike Silbersack Date: Sun, 6 Jan 2002 06:50:54 +0000 Subject: [PATCH] Reorder a calculation in sbreserve so that it does not overflow with multi-megabyte socket buffer sizes. PR: 7420 MFC after: 3 weeks --- sys/kern/uipc_sockbuf.c | 4 +++- sys/kern/uipc_socket2.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c index dc1f4cb027ee..305aaadd8579 100644 --- a/sys/kern/uipc_sockbuf.c +++ b/sys/kern/uipc_sockbuf.c @@ -422,7 +422,9 @@ sbreserve(sb, cc, so, td) * td will only be NULL when we're in an interrupt * (e.g. in tcp_input()) */ - if ((u_quad_t)cc > (u_quad_t)sb_max * MCLBYTES / (MSIZE + MCLBYTES)) + if (sb_max < MSIZE + MCLBYTES) + sb_max = MSIZE + MCLBYTES; + if ((u_quad_t)cc > (u_quad_t)(MCLBYTES * (sb_max / (MSIZE + MCLBYTES)))) return (0); if (!chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, cc, td ? td->td_proc->p_rlimit[RLIMIT_SBSIZE].rlim_cur : RLIM_INFINITY)) { diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index dc1f4cb027ee..305aaadd8579 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -422,7 +422,9 @@ sbreserve(sb, cc, so, td) * td will only be NULL when we're in an interrupt * (e.g. in tcp_input()) */ - if ((u_quad_t)cc > (u_quad_t)sb_max * MCLBYTES / (MSIZE + MCLBYTES)) + if (sb_max < MSIZE + MCLBYTES) + sb_max = MSIZE + MCLBYTES; + if ((u_quad_t)cc > (u_quad_t)(MCLBYTES * (sb_max / (MSIZE + MCLBYTES)))) return (0); if (!chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, cc, td ? td->td_proc->p_rlimit[RLIMIT_SBSIZE].rlim_cur : RLIM_INFINITY)) {