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.
This commit is contained in:
Sebastian Huber
2020-03-09 17:15:20 +01:00
parent 85c9145f09
commit 83994913b6
4 changed files with 2 additions and 40 deletions
+1 -1
View File
@@ -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;
+1 -2
View File
@@ -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 \
-35
View File
@@ -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;
}
-2
View File
@@ -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