From 8ef51b0474b66b9dfbadf487700d8a45f2a65d71 Mon Sep 17 00:00:00 2001 From: Gao Xiang Date: Tue, 17 Sep 2024 17:11:15 +0800 Subject: [PATCH] erofs-utils: lib: fix off-by-one issue with invalid device ID The device ID should be no less than `1 + number of blobs`. In other words, it should be greater than `number of blobs`. Fixes: 89dfe997c2ee ("erofs-utils: lib: fix global-buffer-overflow due to invalid device") Signed-off-by: Gao Xiang Link: https://lore.kernel.org/r/20240917091115.3920734-1-hsiangkao@linux.alibaba.com --- lib/io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/io.c b/lib/io.c index b101c07..dacf8dc 100644 --- a/lib/io.c +++ b/lib/io.c @@ -342,7 +342,7 @@ ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id, ssize_t read; if (device_id) { - if (device_id >= sbi->nblobs) { + if (device_id > sbi->nblobs) { erofs_err("invalid device id %d", device_id); return -EIO; } -- 2.34.1