mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:12:44 +00:00 
			
		
		
		
	ProcFS: Reads past the end of a generated file should be zero-length
This commit is contained in:
		
							parent
							
								
									28ee5b0e98
								
							
						
					
					
						commit
						fe1bf067b8
					
				
					 2 changed files with 27 additions and 7 deletions
				
			
		|  | @ -1107,13 +1107,16 @@ ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes | |||
|     } | ||||
| 
 | ||||
|     auto& data = generated_data; | ||||
|     ssize_t nread = 0; | ||||
|     if (data.has_value()) { | ||||
|         nread = min(static_cast<off_t>(data.value().size() - offset), static_cast<off_t>(count)); | ||||
|         memcpy(buffer, data.value().data() + offset, nread); | ||||
|         if (nread == 0 && description && description->generator_cache()) | ||||
|             description->generator_cache().clear(); | ||||
|     } | ||||
|     if (!data.has_value()) | ||||
|         return 0; | ||||
| 
 | ||||
|     if ((size_t)offset >= data.value().size()) | ||||
|         return 0; | ||||
| 
 | ||||
|     ssize_t nread = min(static_cast<off_t>(data.value().size() - offset), static_cast<off_t>(count)); | ||||
|     memcpy(buffer, data.value().data() + offset, nread); | ||||
|     if (nread == 0 && description && description->generator_cache()) | ||||
|         description->generator_cache().clear(); | ||||
| 
 | ||||
|     return nread; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling