mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 08:32:43 +00:00 
			
		
		
		
	Kernel: Get RefPtr<Device> from the DeviceManagement::get_device method
Instead of returning a raw pointer, which could be technically invalid when using it in the caller function, we return a valid RefPtr of such device. This ensures that the code in DevPtsFS is now safe from a rare race condition in which the SlavePTY device is gone but we still have a pointer to it.
This commit is contained in:
		
							parent
							
								
									5dcf03ad9a
								
							
						
					
					
						commit
						11ead5c84f
					
				
					 6 changed files with 24 additions and 16 deletions
				
			
		|  | @ -23,7 +23,7 @@ DevPtsFS::~DevPtsFS() = default; | |||
| 
 | ||||
| ErrorOr<void> DevPtsFS::initialize() | ||||
| { | ||||
|     m_root_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevPtsFSInode(*this, 1, nullptr))); | ||||
|     m_root_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevPtsFSInode(*this))); | ||||
|     m_root_inode->m_metadata.inode = { fsid(), 1 }; | ||||
|     m_root_inode->m_metadata.mode = 0040555; | ||||
|     m_root_inode->m_metadata.uid = 0; | ||||
|  | @ -55,15 +55,15 @@ ErrorOr<NonnullRefPtr<Inode>> DevPtsFS::get_inode(InodeIdentifier inode_id) cons | |||
|         return *m_root_inode; | ||||
| 
 | ||||
|     unsigned pty_index = inode_index_to_pty_index(inode_id.index()); | ||||
|     auto* device = DeviceManagement::the().get_device(201, pty_index); | ||||
|     auto device = DeviceManagement::the().get_device(201, pty_index); | ||||
|     VERIFY(device); | ||||
| 
 | ||||
|     auto* pts_device = static_cast<SlavePTY*>(device); | ||||
|     auto& pts_device = static_cast<SlavePTY&>(*device); | ||||
|     auto inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevPtsFSInode(const_cast<DevPtsFS&>(*this), inode_id.index(), pts_device))); | ||||
|     inode->m_metadata.inode = inode_id; | ||||
|     inode->m_metadata.size = 0; | ||||
|     inode->m_metadata.uid = pts_device->uid(); | ||||
|     inode->m_metadata.gid = pts_device->gid(); | ||||
|     inode->m_metadata.uid = pts_device.uid(); | ||||
|     inode->m_metadata.gid = pts_device.gid(); | ||||
|     inode->m_metadata.mode = 0020600; | ||||
|     inode->m_metadata.major_device = device->major(); | ||||
|     inode->m_metadata.minor_device = device->minor(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Liav A
						Liav A