libbb: add sanity check in bb_arg_max()
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 24 Dec 2014 00:46:29 +0000 (01:46 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 24 Dec 2014 00:46:29 +0000 (01:46 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/sysconf.c

index cfad9cdc08a0aaa4ede4ec6a8b0ad8bab144abe5..8c1caef5cd73e7d367d1af261a6137b98d59b4e7 100644 (file)
 #if !defined(bb_arg_max)
 unsigned FAST_FUNC bb_arg_max(void)
 {
-       return sysconf(_SC_ARG_MAX);
+       long r = sysconf(_SC_ARG_MAX);
+
+       /* I've seen a version of uclibc which returned -1.
+        * Guard about it, and also avoid insanely large values
+        */
+       if ((unsigned long)r > 64*1024*1024)
+               r = 64*1024*1024;
+
+       return r;
 }
 #endif