summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2015-06-12 16:37:31 +0200
committerDavid Sterba <dsterba@suse.cz>2015-06-15 14:09:10 +0200
commita245463281dda8a3f383e66a8429d913e4f50964 (patch)
treea10263846c88af01d3e92ccf1836da0b87f14e34
parent210bd3a693d92f3327ad42f98c3faba100cec4e3 (diff)
btrfs-progs: receive: use static buffer for source file
We should copy the optarg anyway. Signed-off-by: David Sterba <dsterba@suse.cz>
-rw-r--r--cmds-receive.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/cmds-receive.c b/cmds-receive.c
index 8908f8f7..da57c9ed 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -1096,7 +1096,7 @@ out:
int cmd_receive(int argc, char **argv)
{
char *tomnt = NULL;
- char *fromfile = NULL;
+ char fromfile[PATH_MAX];
char realmnt[PATH_MAX];
struct btrfs_receive r;
int receive_fd = fileno(stdin);
@@ -1109,6 +1109,7 @@ int cmd_receive(int argc, char **argv)
r.dest_dir_fd = -1;
r.dest_dir_chroot = 0;
realmnt[0] = 0;
+ fromfile[0] = 0;
while (1) {
int c;
@@ -1127,7 +1128,13 @@ int cmd_receive(int argc, char **argv)
g_verbose++;
break;
case 'f':
- fromfile = optarg;
+ if (arg_copy_path(fromfile, optarg, sizeof(fromfile))) {
+ fprintf(stderr,
+ "ERROR: input file path too long (%zu)\n",
+ strlen(optarg));
+ ret = 1;
+ goto out;
+ }
break;
case 'e':
r.honor_end_cmd = 1;
@@ -1159,7 +1166,7 @@ int cmd_receive(int argc, char **argv)
tomnt = argv[optind];
- if (fromfile) {
+ if (fromfile[0]) {
receive_fd = open(fromfile, O_RDONLY | O_NOATIME);
if (receive_fd < 0) {
fprintf(stderr, "ERROR: failed to open %s\n", fromfile);