[rtems commit] imfs: Constify imfs_memfile_bytes_per_block

Sebastian Huber sebh at rtems.org
Mon Mar 9 17:59:54 UTC 2020


Module:    rtems
Branch:    master
Commit:    83994913b6603c3a0dbb5ece4b3b5b47457ed99e
Changeset: http://git.rtems.org/rtems/commit/?id=83994913b6603c3a0dbb5ece4b3b5b47457ed99e

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Mar  5 21:48:10 2020 +0100

imfs: Constify imfs_memfile_bytes_per_block

The CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK value is validated by
<rtems/confdefs/libio.h>.  Changing this value during runtime could lead
to memory corruption.

Update #3894.

---

 cpukit/include/rtems/confdefs/libio.h  |  2 +-
 cpukit/include/rtems/imfs.h            |  3 +--
 cpukit/libfs/src/imfs/imfs_initsupp.c  | 35 ----------------------------------
 cpukit/libfs/src/imfs/imfs_stat_file.c |  2 --
 4 files changed, 2 insertions(+), 40 deletions(-)

diff --git a/cpukit/include/rtems/confdefs/libio.h b/cpukit/include/rtems/confdefs/libio.h
index aced98b..3c45771 100644
--- a/cpukit/include/rtems/confdefs/libio.h
+++ b/cpukit/include/rtems/confdefs/libio.h
@@ -196,7 +196,7 @@ static const devFS_data _Filesystem_Root_data = {
   #error "CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK must be a power of two between 16 and 512"
 #endif
 
-int imfs_rq_memfile_bytes_per_block = CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK;
+const int imfs_memfile_bytes_per_block = CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK;
 
 static IMFS_fs_info_t _IMFS_fs_info;
 
diff --git a/cpukit/include/rtems/imfs.h b/cpukit/include/rtems/imfs.h
index 565d103..09e8bd4 100644
--- a/cpukit/include/rtems/imfs.h
+++ b/cpukit/include/rtems/imfs.h
@@ -66,8 +66,7 @@ typedef struct IMFS_jnode_tt IMFS_jnode_t;
  *  @endcode
  */
 #define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK     128
-  extern int imfs_rq_memfile_bytes_per_block;
-  extern int imfs_memfile_bytes_per_block;
+  extern const int imfs_memfile_bytes_per_block;
 
 #define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
 #define IMFS_MEMFILE_BLOCK_SLOTS \
diff --git a/cpukit/libfs/src/imfs/imfs_initsupp.c b/cpukit/libfs/src/imfs/imfs_initsupp.c
index 124a162..58ec41f 100644
--- a/cpukit/libfs/src/imfs/imfs_initsupp.c
+++ b/cpukit/libfs/src/imfs/imfs_initsupp.c
@@ -21,35 +21,6 @@
 #include <rtems/imfs.h>
 
 #include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-static int IMFS_determine_bytes_per_block(
-  int *dest_bytes_per_block,
-  int requested_bytes_per_block,
-  int default_bytes_per_block
-)
-{
-  bool is_valid = false;
-  int bit_mask;
-
-  /*
-   * check, whether requested bytes per block is valid
-   */
-  for (bit_mask = 16; !is_valid && (bit_mask <= 512); bit_mask <<= 1) {
-    if (bit_mask == requested_bytes_per_block) {
-      is_valid = true;
-      break;
-    }
-    if(bit_mask > requested_bytes_per_block)
-      break;
-  }
-  *dest_bytes_per_block = ((is_valid)
-			   ? requested_bytes_per_block
-			   : default_bytes_per_block);
-  return 0;
-}
 
 int IMFS_initialize_support(
   rtems_filesystem_mount_table_entry_t *mt_entry,
@@ -78,12 +49,6 @@ int IMFS_initialize_support(
   mt_entry->mt_fs_root->location.node_access = root_node;
   IMFS_Set_handlers( &mt_entry->mt_fs_root->location );
 
-  IMFS_determine_bytes_per_block(
-    &imfs_memfile_bytes_per_block,
-    imfs_rq_memfile_bytes_per_block,
-    IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK
-  );
-
   return 0;
 }
 
diff --git a/cpukit/libfs/src/imfs/imfs_stat_file.c b/cpukit/libfs/src/imfs/imfs_stat_file.c
index 0135fe4..ef1d009 100644
--- a/cpukit/libfs/src/imfs/imfs_stat_file.c
+++ b/cpukit/libfs/src/imfs/imfs_stat_file.c
@@ -19,8 +19,6 @@
 
 #include <rtems/imfs.h>
 
-int imfs_memfile_bytes_per_block;
-
 int IMFS_stat_file(
   const rtems_filesystem_location_info_t *loc,
   struct stat *buf



More information about the vc mailing list