vlib: clib_panic if sysconf() can't determine page size on startup 29/37129/4
authorAndrew Yourtchenko <ayourtch@gmail.com>
Thu, 15 Sep 2022 11:56:50 +0000 (11:56 +0000)
committerDamjan Marion <dmarion@0xa5.net>
Fri, 2 Dec 2022 13:49:11 +0000 (13:49 +0000)
Account for the potential of sysconf() returning -1 if it can not
get the page size and make it a fatal error.

Coverity: 277313
Type: fix
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
Change-Id: I8cae6a35ec2f745c37f1fe6557e5fa66720b4628

src/vppinfra/linux/mem.c

index ec3328d..69f4363 100644 (file)
@@ -103,6 +103,7 @@ void
 clib_mem_main_init ()
 {
   clib_mem_main_t *mm = &clib_mem_main;
+  long sysconf_page_size;
   uword page_size;
   void *va;
   int fd;
@@ -111,7 +112,12 @@ clib_mem_main_init ()
     return;
 
   /* system page size */
-  page_size = sysconf (_SC_PAGESIZE);
+  sysconf_page_size = sysconf (_SC_PAGESIZE);
+  if (sysconf_page_size < 0)
+    {
+      clib_panic ("Could not determine the page size");
+    }
+  page_size = sysconf_page_size;
   mm->log2_page_sz = min_log2 (page_size);
 
   /* default system hugeppage size */