summaryrefslogtreecommitdiff
path: root/cmds-receive.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-11-29 16:07:19 +0100
committerDavid Sterba <dsterba@suse.com>2016-11-30 12:42:22 +0100
commit71f220034d0ae99d398423ab27e78847e5c02f09 (patch)
tree08a131084c457ac1248dad10a0e8d5c823fdc9c4 /cmds-receive.c
parentd960f81d8e1772dd5c0044e80eb5664b9fbf7c72 (diff)
btrfs-progs: receive: properly detect end of stream conditions
Read buffer helper mistakenly reported end of data as an error. Next, we have to check if the first stream exists as an empty file is not a valid stream. Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-receive.c')
-rw-r--r--cmds-receive.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/cmds-receive.c b/cmds-receive.c
index 62a79850..781dce9b 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -1061,6 +1061,7 @@ static int do_receive(struct btrfs_receive *r, const char *tomnt,
char *dest_dir_full_path;
char root_subvol_path[PATH_MAX];
int end = 0;
+ int count;
dest_dir_full_path = realpath(tomnt, NULL);
if (!dest_dir_full_path) {
@@ -1155,6 +1156,7 @@ static int do_receive(struct btrfs_receive *r, const char *tomnt,
if (ret < 0)
goto out;
+ count = 0;
while (!end) {
if (r->cached_capabilities_len) {
if (g_verbose >= 3)
@@ -1169,6 +1171,13 @@ static int do_receive(struct btrfs_receive *r, const char *tomnt,
max_errors);
if (ret < 0)
goto out;
+ /* Empty stream is invalid */
+ if (ret && count == 0) {
+ error("empty stream is not considered valid");
+ ret = -EINVAL;
+ goto out;
+ }
+ count++;
if (ret)
end = 1;