From 0c77123eeeadae9e8a02461d1fb4d023fbf3aa47 Mon Sep 17 00:00:00 2001 From: Roy Kupershmid Date: Sat, 31 Aug 2019 16:57:56 +0300 Subject: [PATCH] lfs: Validate lfs-cfg sizes before performing arithmetic logics with them --- lfs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lfs.c b/lfs.c index b10c186..e6ad1c3 100644 --- a/lfs.c +++ b/lfs.c @@ -3369,6 +3369,12 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) { lfs->cfg = cfg; int err = 0; + // validate that the lfs-cfg sizes were initiated properly before + // performing any arithmetic logics with them + LFS_ASSERT(lfs->cfg->read_size != 0); + LFS_ASSERT(lfs->cfg->prog_size != 0); + LFS_ASSERT(lfs->cfg->cache_size != 0); + // check that block size is a multiple of cache size is a multiple // of prog and read sizes LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->read_size == 0);