summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-03-05 21:48:10 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-03-09 17:15:20 +0100
commit83994913b6603c3a0dbb5ece4b3b5b47457ed99e (patch)
treea2684dcdfbcc0172140a4c9828c734497ff4695e
parent85c9145f09c3d221cec13922b5507818654b3c2e (diff)
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.
-rw-r--r--cpukit/include/rtems/confdefs/libio.h2
-rw-r--r--cpukit/include/rtems/imfs.h3
-rw-r--r--cpukit/libfs/src/imfs/imfs_initsupp.c35
-rw-r--r--cpukit/libfs/src/imfs/imfs_stat_file.c2
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