summaryrefslogtreecommitdiff
path: root/btrfsctl.c
diff options
context:
space:
mode:
authorEric Sandeen <sandeen@redhat.com>2013-01-25 13:27:47 -0600
committerZach Brown <zab@redhat.com>2013-02-05 16:09:41 -0800
commitbcb2b73358f1c05e6b5c48cfd19e3762cc69c677 (patch)
tree0527a68a1c20f3777f1c5f3559e29c424fb4dde4 /btrfsctl.c
parent7ced17b07f9524c999395240458a46e403036d6b (diff)
btrfs-progs: simplify ioctl name copy and null termination
In the places where we copy a string into the name member of btrfs_ioctl_vol_args or btrfs_ioctl_vol_args_v2, we use strncopy (to not overflow the name array) and then set the last position to the null character. Howver, in both cases the arrays are defined with: char name[MAX+1]; hence the last array position is name[MAX]. In most cases, we now insert the null at name[MAX-1] which deprives us of one useful character. Even the above isn't consistent through the code, so make some helper code to make it simple, i.e. strncpy_null(dest, src) which automatically does the right thing based on the size of dest. Thanks to Zach Brown for the macro suggestion. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Diffstat (limited to 'btrfsctl.c')
-rw-r--r--btrfsctl.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/btrfsctl.c b/btrfsctl.c
index 049a5f35..8fd8cc32 100644
--- a/btrfsctl.c
+++ b/btrfsctl.c
@@ -242,10 +242,9 @@ int main(int ac, char **av)
fd = btrfsctl_open_file_or_dir(fname);
}
- if (name) {
- strncpy(args.name, name, BTRFS_PATH_NAME_MAX + 1);
- args.name[BTRFS_PATH_NAME_MAX] = 0;
- } else
+ if (name)
+ strncpy_null(args.name, name);
+ else
args.name[0] = '\0';
if (command == BTRFS_IOC_SNAP_CREATE) {