From b88b3b46cf1cfd4f0682374918fb3ba4aa0decdd Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 2 May 2024 12:23:44 -0400 Subject: libext2fs: fix potential divide by zero bug caused by a lxcfs bug If sysconf(_SC_NPROCESSORS_CONF) returns zero, this can cause a divide by zero. Make ext2fs_rw_bitmaps() more robust defaulting to 4 threads if _SC_NPROCESSORS_CONF returns an invalid value. https://github.com/tytso/e2fsprogs/issues/114 Signed-off-by: Theodore Ts'o --- lib/ext2fs/rw_bitmaps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c index 1fe65f744..1da75e4a0 100644 --- a/lib/ext2fs/rw_bitmaps.c +++ b/lib/ext2fs/rw_bitmaps.c @@ -557,7 +557,7 @@ errcode_t ext2fs_rw_bitmaps(ext2_filsys fs, int flags, int num_threads) * MacOS, FreeBSD, etc. * ref: https://stackoverflow.com/questions/150355 */ - if (num_threads < 0) + if (num_threads <= 0) num_threads = 4; if ((unsigned) num_threads > fs->group_desc_count) -- cgit 1.2.3-korg