From fefbab75208e570b26b45481db3e5ced6e9e0853 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 15 Nov 2016 15:22:42 +0100 Subject: [PATCH] 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 --- send-stream.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/send-stream.c b/send-stream.c index d2de9d39..80bf680b 100644 --- a/send-stream.c +++ b/send-stream.c @@ -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; }