[PATCH 2/5] imfs: Constify imfs_memfile_bytes_per_block
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Mar 6 06:47:57 UTC 2020
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 aced98b3b9..3c45771952 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 565d103226..09e8bd4a9d 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 124a1622c9..58ec41f269 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 0135fe43e3..ef1d0095a6 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
--
2.16.4
More information about the devel
mailing list