summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2015-11-13 18:20:38 +0100
committerDavid Sterba <dsterba@suse.com>2015-11-16 14:23:46 +0100
commit882f319761ebe0ff17624e6b66ff79270c3c63e5 (patch)
tree7bf48cc7eb4a015cc283fc70d7ca3c675ebbd136 /utils.c
parent0cf3b78f404b01b6e400fac6eb29890fc430b20e (diff)
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>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/utils.c b/utils.c
index 4f3fbbae..c9c6394f 100644
--- a/utils.c
+++ b/utils.c
@@ -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;