session: fix segment size rounding and size init 77/19477/1
authorFlorin Coras <fcoras@cisco.com>
Thu, 9 May 2019 21:11:38 +0000 (14:11 -0700)
committerFlorin Coras <fcoras@cisco.com>
Thu, 9 May 2019 21:11:38 +0000 (14:11 -0700)
Change-Id: Iceb2a46802ed13f319cb16f1df236b11dc3c00f6
Signed-off-by: Florin Coras <fcoras@cisco.com>
src/vnet/session/application.c
src/vnet/session/segment_manager.c

index 82b6dfe..19a67ba 100644 (file)
@@ -554,7 +554,7 @@ application_alloc_and_init (app_init_args_t * a)
 
   props = application_segment_manager_properties (app);
   segment_manager_properties_init (props);
-  props->segment_size = options[APP_OPTIONS_ADD_SEGMENT_SIZE];
+  props->segment_size = options[APP_OPTIONS_SEGMENT_SIZE];
   props->prealloc_fifos = options[APP_OPTIONS_PREALLOC_FIFO_PAIRS];
   if (options[APP_OPTIONS_ADD_SEGMENT_SIZE])
     {
index c8d4be5..f7b4c31 100644 (file)
@@ -224,7 +224,9 @@ segment_manager_add_segment (segment_manager_t * sm, u32 segment_size)
    */
   segment_size = segment_size ? segment_size : props->add_segment_size;
   page_size = clib_mem_get_page_size ();
-  segment_size = (segment_size + page_size - 1) & ~(page_size - 1);
+  /* Protect against segment size u32 wrap */
+  segment_size = clib_max (segment_size + page_size - 1, segment_size);
+  segment_size = segment_size & ~(page_size - 1);
   if (props->segment_type != SSVM_SEGMENT_PRIVATE)
     {
       seg_name = format (0, "%d-%d%c", getpid (), segment_name_counter++, 0);