From: Theodore Ts'o Date: Thu, 2 May 2024 16:23:44 +0000 (-0400) Subject: libext2fs: fix potential divide by zero bug caused by a lxcfs bug X-Git-Tag: v1.47.1~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b88b3b46cf1cfd4f0682374918fb3ba4aa0decdd;p=thirdparty%2Fe2fsprogs.git 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 --- diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c index 1fe65f74..1da75e4a 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)