Whamcloud - gitweb
libext2fs: fix potential divide by zero bug caused by a lxcfs bug
authorTheodore Ts'o <tytso@mit.edu>
Thu, 2 May 2024 16:23:44 +0000 (12:23 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 2 May 2024 16:23:44 +0000 (12:23 -0400)
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 <tytso@mit.edu>
lib/ext2fs/rw_bitmaps.c

index 1fe65f7..1da75e4 100644 (file)
@@ -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)