From c52d16098c5fbc12a4edd01ba62e5c4cd5d1a336 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 18 Jan 2021 16:04:18 +0100 Subject: [PATCH] ipcs: fallback for overflow The previous commit 7a08784ab053d6aa30db990cbec1fd35b34ed00a reduced number of situation when we need fallback when kbytes calculated for shmall pages, but there is still possible to see overflows. This patch add fallback also for kbytes. Signed-off-by: Karel Zak --- sys-utils/ipcs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c index 79a6516e6..673027222 100644 --- a/sys-utils/ipcs.c +++ b/sys-utils/ipcs.c @@ -217,9 +217,11 @@ static void do_shm (char format, int unit) _("max seg size"), lim.shmmax, "\n", 0); if (unit == IPC_UNIT_KB || unit == IPC_UNIT_DEFAULT) { - ipc_print_size(IPC_UNIT_DEFAULT, - _("max total shared memory (kbytes)"), (pgsz / 1024) * - (uint64_t) lim.shmall, "\n", 0); + tmp = (uint64_t) lim.shmall * (pgsz / 1024); + if (lim.shmall != 0 && tmp / lim.shmall != pgsz / 1024) + tmp = UINT64_MAX - (UINT64_MAX % (pgsz / 1024)); + + ipc_print_size(IPC_UNIT_DEFAULT, _("max total shared memory (kbytes)"), tmp, "\n", 0); } else { tmp = (uint64_t) lim.shmall * pgsz;