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>
This commit is contained in:
parent
d960f81d8e
commit
71f220034d
|
@ -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;
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ static int read_buf(struct btrfs_send_stream *sctx, char *buf, size_t len)
|
|||
ret = 0;
|
||||
|
||||
out_eof:
|
||||
if (pos < len) {
|
||||
if (0 < pos && pos < len) {
|
||||
error("short read from stream: expected %zu read %zu", len, pos);
|
||||
ret = -EIO;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue