strip down get_len() to a call to rand32()
PATCH 7/7 strip down get_len() to a call to rand32()
From: Tyson Smith <[email protected]>
The body of get_len() was the same as rand32() so applying it to a value from rand32() didn't offer much value. A switch case could be added that generates other length like values as well. This could include 2^n +/- ~2, page_size +/- 1, MAX_INT... etc.
--- random-length.c | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-)
random-length.c +1 -39
@@ -1,45 +1,7 @@ -#include <stdlib.h> - -#include "arch.h" // page_size #include "sanitise.h" #include "random.h" unsigned long get_len (void ) { -int i =0 ; - - i =rand32 (); - -/* short circuit if 0 */ -if (i ==0 ) -return 0 ; - -switch (rand () %6 ) { - -case 0 : i &=0xff ; -break ; -case 1 : i &= page_size -1 ; -break ; -case 2 : i &=0xffff ; -break ; -case 3 : i &=0xffffff ; -break ; -case 4 : i &=0xffffffff ; -break ; -case 5 : -// Pass through -break ; - } - -/* again, short circuit if 0 */ -if (i ==0 ) -return 0 ; - -/* we might get lucky if something is counting ints/longs etc. */ -if (ONE_IN (4 )) { -int _div =1 <<RAND_RANGE (1 ,4 );/* 2,4,8 or 16 */ - i /= _div; - } - -return i; +return rand32 (); }
Signature · 1 line
1.9.1
Quoted 6 lines · On Mon, Mar 16, 2015 at 01:27:07PM -0700, [email protected] wrote:
From: Tyson Smith <[email protected]>
The body of
get_len()was the same asrand32()so applying it to a value fromrand32()didn't offer much value. A switch case could be added that generates other length like values as well. This could include 2^n +/- ~2,page_size+/- 1,MAX_INT... etc.
Makes sense, but we could go a step further, and just remove random-length.c entirely, and have generate-args.c just do the rand32 call. (same for the 2-3 syscalls that call it)
Dave