mirror of
				git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
				synced 2025-10-31 16:54:21 +00:00 
			
		
		
		
	tools/nolibc: Fix strlcpy() return code and size usage
The return code should always be strlen(src), and we should copy at most size-1 bytes. While we are there, make sure to null-terminate the dst buffer if we copied something. Signed-off-by: Rodrigo Campos <rodrigo@sdfg.com.ar> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
This commit is contained in:
		
							parent
							
								
									34d232c39a
								
							
						
					
					
						commit
						fbffce819e
					
				
					 1 changed files with 10 additions and 8 deletions
				
			
		|  | @ -219,16 +219,18 @@ static __attribute__((unused)) | |||
| size_t strlcpy(char *dst, const char *src, size_t size) | ||||
| { | ||||
| 	size_t len; | ||||
| 	char c; | ||||
| 
 | ||||
| 	for (len = 0;;) { | ||||
| 		c = src[len]; | ||||
| 		if (len < size) | ||||
| 			dst[len] = c; | ||||
| 		if (!c) | ||||
| 			break; | ||||
| 		len++; | ||||
| 	for (len = 0; len < size; len++) { | ||||
| 		dst[len] = src[len]; | ||||
| 		if (!dst[len]) | ||||
| 			return len; | ||||
| 	} | ||||
| 	if (size) | ||||
| 		dst[size-1] = '\0'; | ||||
| 
 | ||||
| 	while (src[len]) | ||||
| 		len++; | ||||
| 
 | ||||
| 	return len; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Rodrigo Campos
						Rodrigo Campos