btrfs-progs: send-stream: check number of read bytes from stream

The read_buf does not verify that we've read the expected number of
bytes.  A corrupted of malformated stream will not be detdcted.

Signed-off-by: David Sterba <dsterba@suse.com>
master
David Sterba 2016-11-15 15:22:42 +01:00
parent 028476f19c
commit fefbab7520
1 changed files with 7 additions and 2 deletions

View File

@ -61,13 +61,18 @@ static int read_buf(struct btrfs_send_stream *sctx, char *buf, size_t len)
}
if (rbytes == 0) {
ret = 1;
goto out;
goto out_eof;
}
pos += rbytes;
}
ret = 0;
out_eof:
if (pos < len) {
error("short read from stream: expected %zu read %zu", len, pos);
ret = -EIO;
}
out:
return ret;
}