[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#200885: [PATCH] fix init's check_free_memory



Package: busybox-cvs
Version: 0.60.99.cvs20030426-9 (not installed)
Severity: important
Tags: upstream patch

Hi,

check_free_memory() is init/init.c is broken. While I really think it
should be more careful about overflows, I've tried to follow upstream's
will in the patch.

Important severity because it makes d-i boot fail on s390x (I know it is
not a supported arch but I guess you'll find the problem on other archs)

--- busybox-cvs-0.60.99.cvs20030426.orig/init/init.c
+++ busybox-cvs-0.60.99.cvs20030426/init/init.c
@@ -335,7 +335,8 @@
        }
        result = (info.totalram >> s) + (info.totalswap >> s);
        result = result * u;
-       if (result < 0)
+       /* checking for int/unsigned overflows */
+       if (result > INT_MAX || result < u)
                result = INT_MAX;
        return result;
 }

The current code was really broken, result is declared as unsigned ...
IMHO, result should be an unsigned long long to avoid overflows and
numerous checks. 

But the patched code should work for now assuming the first operation
does not trigger an overflow...

HTH.

Guillaume.

-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux belette 2.4.20 #17 lun jun 16 14:50:16 EDT 2003 i686
Locale: LANG=fr_FR@euro, LC_CTYPE=fr_FR@euro

-- 
Guillaume Morin <guillaume@morinfr.org>

                We're a couple when our bodies double (Placebo)



Reply to: