]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ipcs: fallback for overflow
authorKarel Zak <kzak@redhat.com>
Mon, 18 Jan 2021 15:04:18 +0000 (16:04 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 18 Jan 2021 15:04:18 +0000 (16:04 +0100)
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 <kzak@redhat.com>
sys-utils/ipcs.c

index 79a6516e6872a4821b7d7ee4fa4c407f1edebe2b..6730272221c23ef487cfd655bb180a504f920bab 100644 (file)
@@ -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;