* [PATCH 7/7] strip down get_len() to a call to rand32()
@ 2015-03-16 20:27 tyson.w.smith
2015-03-17 14:38 ` Dave Jones
0 siblings, 1 reply; 2+ messages in thread
From: tyson.w.smith @ 2015-03-16 20:27 UTC (permalink / raw)
To: davej; +Cc: trinity, tysmith, Tyson Smith
From: Tyson Smith <tyson.w.smith@gmail.com>
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(-)
diff --git a/random-length.c b/random-length.c
index a1a72e3..1ef3dd2 100644
--- a/random-length.c
+++ b/random-length.c
@@ -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();
}
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 7/7] strip down get_len() to a call to rand32()
2015-03-16 20:27 [PATCH 7/7] strip down get_len() to a call to rand32() tyson.w.smith
@ 2015-03-17 14:38 ` Dave Jones
0 siblings, 0 replies; 2+ messages in thread
From: Dave Jones @ 2015-03-17 14:38 UTC (permalink / raw)
To: tyson.w.smith; +Cc: trinity, tysmith
On Mon, Mar 16, 2015 at 01:27:07PM -0700, tyson.w.smith@gmail.com wrote:
> From: Tyson Smith <tyson.w.smith@gmail.com>
>
> 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.
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-03-17 14:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-16 20:27 [PATCH 7/7] strip down get_len() to a call to rand32() tyson.w.smith
2015-03-17 14:38 ` Dave Jones
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.