mirror of
				https://git.proxmox.com/git/mirror_zfs.git
				synced 2025-10-26 18:05:04 +03:00 
			
		
		
		
	Fix -Wformat-overflow warning in zfs_project_handle_dir()
Switch to using asprintf() to satisfy the compiler and resolve the
potential format-overflow warning.  Not the conditional before the
sprintf() would have prevented this regardless.
    cmd/zfs/zfs_project.c: In function ‘zfs_project_handle_dir’:
    cmd/zfs/zfs_project.c:241:38: error: ‘/’ directive writing
    1 byte into a region of size between 0 and 4352
    [-Werror=format-overflow=]
    cmd/zfs/zfs_project.c:241:17: note: ‘sprintf’ output between
    2 and 4609 bytes into a destination of size 4352
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13528
Closes #13575
			
			
This commit is contained in:
		
							parent
							
								
									d483ef3744
								
							
						
					
					
						commit
						d2ff2196a5
					
				| @ -207,7 +207,6 @@ static int | |||||||
| zfs_project_handle_dir(const char *name, zfs_project_control_t *zpc, | zfs_project_handle_dir(const char *name, zfs_project_control_t *zpc, | ||||||
|     list_t *head) |     list_t *head) | ||||||
| { | { | ||||||
| 	char fullname[PATH_MAX]; |  | ||||||
| 	struct dirent *ent; | 	struct dirent *ent; | ||||||
| 	DIR *dir; | 	DIR *dir; | ||||||
| 	int ret = 0; | 	int ret = 0; | ||||||
| @ -227,21 +226,28 @@ zfs_project_handle_dir(const char *name, zfs_project_control_t *zpc, | |||||||
| 	zpc->zpc_ignore_noent = B_TRUE; | 	zpc->zpc_ignore_noent = B_TRUE; | ||||||
| 	errno = 0; | 	errno = 0; | ||||||
| 	while (!ret && (ent = readdir(dir)) != NULL) { | 	while (!ret && (ent = readdir(dir)) != NULL) { | ||||||
|  | 		char *fullname; | ||||||
|  | 
 | ||||||
| 		/* skip "." and ".." */ | 		/* skip "." and ".." */ | ||||||
| 		if (strcmp(ent->d_name, ".") == 0 || | 		if (strcmp(ent->d_name, ".") == 0 || | ||||||
| 		    strcmp(ent->d_name, "..") == 0) | 		    strcmp(ent->d_name, "..") == 0) | ||||||
| 			continue; | 			continue; | ||||||
| 
 | 
 | ||||||
| 		if (strlen(ent->d_name) + strlen(name) >= | 		if (strlen(ent->d_name) + strlen(name) + 1 >= PATH_MAX) { | ||||||
| 		    sizeof (fullname) + 1) { |  | ||||||
| 			errno = ENAMETOOLONG; | 			errno = ENAMETOOLONG; | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		sprintf(fullname, "%s/%s", name, ent->d_name); | 		if (asprintf(&fullname, "%s/%s", name, ent->d_name) == -1) { | ||||||
|  | 			errno = ENOMEM; | ||||||
|  | 			break; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		ret = zfs_project_handle_one(fullname, zpc); | 		ret = zfs_project_handle_one(fullname, zpc); | ||||||
| 		if (!ret && zpc->zpc_recursive && ent->d_type == DT_DIR) | 		if (!ret && zpc->zpc_recursive && ent->d_type == DT_DIR) | ||||||
| 			zfs_project_item_alloc(head, fullname); | 			zfs_project_item_alloc(head, fullname); | ||||||
|  | 
 | ||||||
|  | 		free(fullname); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (errno && !ret) { | 	if (errno && !ret) { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Brian Behlendorf
						Brian Behlendorf