btrfs-progs: utils: do not expect lo_file_name to be null terminated

The loop_info64::lo_file_name might not be null terminated. Avoid strlen
and trim the length to whatever size of the loop_info buffer.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2015-11-13 18:20:38 +01:00
parent 0cf3b78f40
commit 882f319761
1 changed files with 2 additions and 1 deletions

View File

@ -1188,7 +1188,8 @@ static int resolve_loop_device_with_loopdev(const char* loop_dev, char* loop_fil
if (ioctl(fd, LOOP_GET_STATUS64, &lo64) < 0)
return -errno;
memcpy(loop_file, lo64.lo_file_name, strlen(lo64.lo_file_name) + 1);
memcpy(loop_file, lo64.lo_file_name, sizeof(lo64.lo_file_name));
loop_file[sizeof(lo64.lo_file_name)] = 0;
if (close(fd) < 0)
return -errno;