mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:02:45 +00:00 
			
		
		
		
	Kernel/TmpFS: Prevent TmpFS::add_child() from adding duplicate children
If asked to add an already existing name to a directory inode, fail with EEXIST, consistent with other filesystems.
This commit is contained in:
		
							parent
							
								
									63e8cf8d59
								
							
						
					
					
						commit
						db4388f21b
					
				
					 1 changed files with 7 additions and 1 deletions
				
			
		|  | @ -271,13 +271,19 @@ ErrorOr<void> TmpFSInode::add_child(Inode& child, StringView name, mode_t) | |||
|     if (name.length() > NAME_MAX) | ||||
|         return ENAMETOOLONG; | ||||
| 
 | ||||
|     MutexLocker locker(m_inode_lock); | ||||
|     for (auto const& existing_child : m_children) { | ||||
|         if (existing_child.name->view() == name) | ||||
|             return EEXIST; | ||||
|     } | ||||
| 
 | ||||
|     auto name_kstring = TRY(KString::try_create(name)); | ||||
|     // Balanced by `delete` in remove_child()
 | ||||
| 
 | ||||
|     auto* child_entry = new (nothrow) Child { move(name_kstring), static_cast<TmpFSInode&>(child) }; | ||||
|     if (!child_entry) | ||||
|         return ENOMEM; | ||||
| 
 | ||||
|     MutexLocker locker(m_inode_lock); | ||||
|     m_children.append(*child_entry); | ||||
|     did_add_child(child.identifier(), name); | ||||
|     return {}; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling