aboutsummaryrefslogtreecommitdiffstats
path: root/cmds-receive.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2015-06-12 15:58:55 +0200
committerDavid Sterba <dsterba@suse.cz>2015-06-15 14:09:09 +0200
commit210bd3a693d92f3327ad42f98c3faba100cec4e3 (patch)
tree0596030c9716466b0c543b28262df540b1262f4b /cmds-receive.c
parent6bfa3cae0590a1ed6a40b20ae48389a89b366fb2 (diff)
downloadbtrfs-progs-210bd3a693d92f3327ad42f98c3faba100cec4e3.tar.gz
btrfs-progs-210bd3a693d92f3327ad42f98c3faba100cec4e3.tar.xz
btrfs-progs-210bd3a693d92f3327ad42f98c3faba100cec4e3.zip
btrfs-progs: receive: use static buffer for mount point option argument
Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'cmds-receive.c')
-rw-r--r--cmds-receive.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/cmds-receive.c b/cmds-receive.c
index 8dcdd29..8908f8f 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -939,7 +939,7 @@ static int do_receive(struct btrfs_receive *r, const char *tomnt,
goto out;
}
- if (realmnt) {
+ if (realmnt[0]) {
r->root_path = realmnt;
} else {
ret = find_mount_root(dest_dir_full_path, &r->root_path);
@@ -1097,7 +1097,7 @@ int cmd_receive(int argc, char **argv)
{
char *tomnt = NULL;
char *fromfile = NULL;
- char *realmnt = NULL;
+ char realmnt[PATH_MAX];
struct btrfs_receive r;
int receive_fd = fileno(stdin);
u64 max_errors = 1;
@@ -1108,6 +1108,7 @@ int cmd_receive(int argc, char **argv)
r.write_fd = -1;
r.dest_dir_fd = -1;
r.dest_dir_chroot = 0;
+ realmnt[0] = 0;
while (1) {
int c;
@@ -1138,10 +1139,11 @@ int cmd_receive(int argc, char **argv)
max_errors = arg_strtou64(optarg);
break;
case 'm':
- free(realmnt);
- realmnt = strdup(optarg);
- if (!realmnt) {
- fprintf(stderr, "ERROR: couldn't allocate realmnt.\n");
+ if (arg_copy_path(realmnt, optarg, sizeof(realmnt))) {
+ fprintf(stderr,
+ "ERROR: mount point path too long (%zu)\n",
+ strlen(optarg));
+ ret = 1;
goto out;
}
break;
@@ -1168,7 +1170,6 @@ int cmd_receive(int argc, char **argv)
ret = do_receive(&r, tomnt, realmnt, receive_fd, max_errors);
out:
- free(realmnt);
return !!ret;
}