diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp index cf13c1bd49..5a6c642910 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp @@ -642,10 +642,23 @@ BlockAllocator::Free(Transaction *transaction, block_run run) // the "chkbfs" command +bool +BlockAllocator::IsValidCheckControl(check_control *control) +{ + if (control == NULL + || control->magic != BFS_IOCTL_CHECK_MAGIC) { + FATAL(("invalid check_control (%p)!\n", control)); + return false; + } + + return true; +} + + status_t BlockAllocator::StartChecking(check_control *control) { - if (control == NULL) + if (!IsValidCheckControl(control)) return B_BAD_VALUE; status_t status = fLock.Lock(); @@ -771,7 +784,7 @@ BlockAllocator::StopChecking(check_control *control) status_t BlockAllocator::CheckNextNode(check_control *control) { - if (control == NULL) + if (!IsValidCheckControl(control)) return B_BAD_VALUE; check_cookie *cookie = (check_cookie *)control->cookie; diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h index ffd47d50b5..e023a5f83a 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h @@ -44,6 +44,7 @@ class BlockAllocator { status_t CheckInode(Inode *inode, check_control *control = NULL); private: + bool IsValidCheckControl(check_control *control); bool CheckBitmapIsUsedAt(off_t block) const; void SetCheckBitmapAt(off_t block); diff --git a/src/add-ons/kernel/file_systems/bfs/bfs_control.h b/src/add-ons/kernel/file_systems/bfs/bfs_control.h index b4a9da8574..858aa54a0f 100644 --- a/src/add-ons/kernel/file_systems/bfs/bfs_control.h +++ b/src/add-ons/kernel/file_systems/bfs/bfs_control.h @@ -34,6 +34,7 @@ extern "C" { * BFS_IOCTL_START_CHECKING is called */ struct check_control { + uint32 magic; uint32 flags; char name[B_FILE_NAME_LENGTH]; vnode_id inode; @@ -69,4 +70,7 @@ struct check_control { #define BFS_WRONG_TYPE 16 #define BFS_NAMES_DONT_MATCH 32 +/* check control magic value */ +#define BFS_IOCTL_CHECK_MAGIC 'BChk' + #endif /* BFS_CONTROL_H */