mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 07:32:44 +00:00 
			
		
		
		
	TmpFS: Reads past the end of a file should be zero-length
This commit is contained in:
		
							parent
							
								
									50056d1d84
								
							
						
					
					
						commit
						28ee5b0e98
					
				
					 2 changed files with 23 additions and 0 deletions
				
			
		|  | @ -160,6 +160,9 @@ ssize_t TmpFSInode::read_bytes(off_t offset, ssize_t size, u8* buffer, FileDescr | |||
|     if (!m_content.has_value()) | ||||
|         return 0; | ||||
| 
 | ||||
|     if (offset >= m_metadata.size) | ||||
|         return 0; | ||||
| 
 | ||||
|     if (static_cast<off_t>(size) > m_metadata.size - offset) | ||||
|         size = m_metadata.size - offset; | ||||
| 
 | ||||
|  |  | |||
|  | @ -121,6 +121,25 @@ void test_mmap_directory() | |||
|     close(fd); | ||||
| } | ||||
| 
 | ||||
| void test_tmpfs_read_past_end() | ||||
| { | ||||
|     int fd = open("/tmp/x", O_RDWR | O_CREAT | O_TRUNC, 0600); | ||||
|     ASSERT(fd >= 0); | ||||
| 
 | ||||
|     int rc = ftruncate(fd, 1); | ||||
|     ASSERT(rc == 0); | ||||
| 
 | ||||
|     rc = lseek(fd, 4096, SEEK_SET); | ||||
|     ASSERT(rc == 4096); | ||||
| 
 | ||||
|     char buffer[16]; | ||||
|     int nread = read(fd, buffer, sizeof(buffer)); | ||||
|     if (nread != 0) { | ||||
|         fprintf(stderr, "Expected 0-length read past end of file in /tmp\n"); | ||||
|     } | ||||
|     close(fd); | ||||
| } | ||||
| 
 | ||||
| int main(int, char**) | ||||
| { | ||||
|     int rc; | ||||
|  | @ -140,6 +159,7 @@ int main(int, char**) | |||
|     test_ftruncate_readonly(); | ||||
|     test_ftruncate_negative(); | ||||
|     test_mmap_directory(); | ||||
|     test_tmpfs_read_past_end(); | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling