mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:32:44 +00:00 
			
		
		
		
	Kernel/Syscalls: Use copy_n_to_user when applicable
copy_to_user() with bytes as the last argument could be changed to using copy_n_to_user() with a count.
This commit is contained in:
		
							parent
							
								
									f32fde6152
								
							
						
					
					
						commit
						d0ac24ddbf
					
				
					 5 changed files with 10 additions and 9 deletions
				
			
		|  | @ -83,7 +83,7 @@ ErrorOr<FlatPtr> Process::sys$getgroups(size_t count, Userspace<GroupID*> user_g | ||||||
|         return credentials->extra_gids().size(); |         return credentials->extra_gids().size(); | ||||||
|     if (count != credentials->extra_gids().size()) |     if (count != credentials->extra_gids().size()) | ||||||
|         return EINVAL; |         return EINVAL; | ||||||
|     TRY(copy_to_user(user_gids, credentials->extra_gids().data(), sizeof(GroupID) * count)); |     TRY(copy_n_to_user(user_gids, credentials->extra_gids().data(), count)); | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -50,11 +50,11 @@ ErrorOr<FlatPtr> Process::sys$getkeymap(Userspace<Syscall::SC_getkeymap_params c | ||||||
|         TRY(copy_to_user(params.map_name.data, keymap_data.character_map_name->characters(), keymap_data.character_map_name->length())); |         TRY(copy_to_user(params.map_name.data, keymap_data.character_map_name->characters(), keymap_data.character_map_name->length())); | ||||||
| 
 | 
 | ||||||
|         auto const& character_maps = keymap_data.character_map; |         auto const& character_maps = keymap_data.character_map; | ||||||
|         TRY(copy_to_user(params.map, character_maps.map, CHAR_MAP_SIZE * sizeof(u32))); |         TRY(copy_n_to_user(params.map, character_maps.map, CHAR_MAP_SIZE)); | ||||||
|         TRY(copy_to_user(params.shift_map, character_maps.shift_map, CHAR_MAP_SIZE * sizeof(u32))); |         TRY(copy_n_to_user(params.shift_map, character_maps.shift_map, CHAR_MAP_SIZE)); | ||||||
|         TRY(copy_to_user(params.alt_map, character_maps.alt_map, CHAR_MAP_SIZE * sizeof(u32))); |         TRY(copy_n_to_user(params.alt_map, character_maps.alt_map, CHAR_MAP_SIZE)); | ||||||
|         TRY(copy_to_user(params.altgr_map, character_maps.altgr_map, CHAR_MAP_SIZE * sizeof(u32))); |         TRY(copy_n_to_user(params.altgr_map, character_maps.altgr_map, CHAR_MAP_SIZE)); | ||||||
|         TRY(copy_to_user(params.shift_altgr_map, character_maps.shift_altgr_map, CHAR_MAP_SIZE * sizeof(u32))); |         TRY(copy_n_to_user(params.shift_altgr_map, character_maps.shift_altgr_map, CHAR_MAP_SIZE)); | ||||||
|         return 0; |         return 0; | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -43,7 +43,8 @@ ErrorOr<FlatPtr> Process::sys$pipe(Userspace<int*> pipefd, int flags) | ||||||
|             reader_fd_allocation.fd, |             reader_fd_allocation.fd, | ||||||
|             writer_fd_allocation.fd, |             writer_fd_allocation.fd, | ||||||
|         }; |         }; | ||||||
|         if (copy_to_user(pipefd, fds_for_userspace, sizeof(fds_for_userspace)).is_error()) { |         if (copy_n_to_user(pipefd, fds_for_userspace, 2).is_error()) { | ||||||
|  |             // Avoid leaking both file descriptors on error.
 | ||||||
|             fds[reader_fd_allocation.fd] = {}; |             fds[reader_fd_allocation.fd] = {}; | ||||||
|             fds[writer_fd_allocation.fd] = {}; |             fds[writer_fd_allocation.fd] = {}; | ||||||
|             return EFAULT; |             return EFAULT; | ||||||
|  |  | ||||||
|  | @ -131,7 +131,7 @@ ErrorOr<FlatPtr> Process::sys$poll(Userspace<Syscall::SC_poll_params const*> use | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (params.nfds > 0) |     if (params.nfds > 0) | ||||||
|         TRY(copy_to_user(¶ms.fds[0], fds_copy.data(), params.nfds * sizeof(pollfd))); |         TRY(copy_n_to_user(¶ms.fds[0], fds_copy.data(), params.nfds)); | ||||||
| 
 | 
 | ||||||
|     return fds_with_revents; |     return fds_with_revents; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -428,7 +428,7 @@ ErrorOr<FlatPtr> Process::sys$socketpair(Userspace<Syscall::SC_socketpair_params | ||||||
|         setup_socket_fd(fds, allocated_fds[0], pair.description0, params.type); |         setup_socket_fd(fds, allocated_fds[0], pair.description0, params.type); | ||||||
|         setup_socket_fd(fds, allocated_fds[1], pair.description1, params.type); |         setup_socket_fd(fds, allocated_fds[1], pair.description1, params.type); | ||||||
| 
 | 
 | ||||||
|         if (copy_to_user(params.sv, allocated_fds, sizeof(allocated_fds)).is_error()) { |         if (copy_n_to_user(params.sv, allocated_fds, 2).is_error()) { | ||||||
|             // Avoid leaking both file descriptors on error.
 |             // Avoid leaking both file descriptors on error.
 | ||||||
|             fds[allocated_fds[0]] = {}; |             fds[allocated_fds[0]] = {}; | ||||||
|             fds[allocated_fds[1]] = {}; |             fds[allocated_fds[1]] = {}; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Pankaj Raghav
						Pankaj Raghav