aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Van Assche <bvanassche@acm.org>2022-06-23 11:12:05 -0700
committerJaegeuk Kim <jaegeuk@kernel.org>2022-07-21 19:27:03 -0700
commit92e2e526090ffbb3f579f5e6ff4cd362454b4122 (patch)
tree2214b5c545634852be099f8910e6535b57d00f01
parent648a49128addf88934b355725eadf21603db7cc5 (diff)
downloadf2fs-tools-92e2e526090ffbb3f579f5e6ff4cd362454b4122.tar.gz
Fix f2fs_report_zone()
The definition of struct blk_zone_report is as follows: struct blk_zone_report { __u64 sector; __u32 nr_zones; __u32 flags; struct blk_zone zones[0]; }; Since f2fs_report_zone() allocates the above data structure with malloc() and since f2fs_report_zone() only initializes the sector and nr_zones members, the flags member is not initialized. Modify f2fs_report_zone() such that 0 is passed as flags to the BLKREPORTZONE ioctl instead of a random value. This has been discovered by reading the source code. Cc: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com> Fixes: 6d7c7b785feb ("libf2fs_zoned: Introduce f2fs_report_zone() helper function") Signed-off-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--lib/libf2fs_zoned.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/libf2fs_zoned.c b/lib/libf2fs_zoned.c
index f383ce2..d8de66b 100644
--- a/lib/libf2fs_zoned.c
+++ b/lib/libf2fs_zoned.c
@@ -206,7 +206,8 @@ int f2fs_report_zone(int i, uint64_t sector, void *blkzone)
struct blk_zone_report *rep;
int ret = -1;
- rep = malloc(sizeof(struct blk_zone_report) + sizeof(struct blk_zone));
+ rep = calloc(1, sizeof(struct blk_zone_report) +
+ sizeof(struct blk_zone));
if (!rep) {
ERR_MSG("No memory for report zones\n");
return -ENOMEM;