diff --git a/fuzzer/Fuzzer.java b/fuzzer/Fuzzer.java index 824236ec1cc4c83a7dc76e6840a24df3e89c6d29..7ee264b0c8ec7aaab92aca83dc3e2efc5d15015e 100644 --- a/fuzzer/Fuzzer.java +++ b/fuzzer/Fuzzer.java @@ -8,15 +8,17 @@ import java.util.Random; public class Fuzzer { private static final String OUTPUT_FILE = "fuzz.txt"; + private static final String CHAR_LOWER = "abcdefghijklmnopqrstuvwxyz"; private static final String CHAR_UPPER = CHAR_LOWER.toUpperCase(); private static final String NUMBER = "0123456789"; - private static final int MAX_STRING_LENGTH = 1014; + + private static final int MAX_LINE_LENGTH = 1022; private static final int MAX_URL_LENGTH = 300; private static final int numInputLines = 1024; //Indicates the number of inputs we wish to generate in one file - private static ArrayList<String> savedURLs = new ArrayList<String>(); + private static ArrayList<String> savedURLs = new ArrayList<String>(); //save put urls here for get and rem - private static final String DATA_FOR_RANDOM_STRING = CHAR_LOWER + CHAR_UPPER + NUMBER; + private static final String DATA_FOR_RANDOM_STRING = CHAR_LOWER + CHAR_UPPER + NUMBER; //specifies which characters can be in a string public static void main(String[] args) throws IOException { System.out.println(Instruction.getBNF()); @@ -91,7 +93,8 @@ public class Fuzzer { input += " "+ url; }else if(op.equals(OperandType.STRING)) { - input += " "+generateRandomString(MAX_STRING_LENGTH); + int maxStringLength = MAX_LINE_LENGTH - input.length() - ((inst.getOperands().length-index)*2); + input += " "+generateRandomString(maxStringLength); } index++; } @@ -115,14 +118,26 @@ public class Fuzzer { * and modified*/ public static String generateRandomString(int maxlength) { if (maxlength < 1) throw new IllegalArgumentException(); + Random random = new Random(); + int minLength = 1; + int length; + + //make a 1/4 chance of picking the max length and a 1/4 chance of picking the min length + int chance = random.nextInt(4); + if(chance == 1) { + length = maxlength; + }else if(chance == 2) { + length = minLength; + }else { + length = random.nextInt(maxlength)+1; + } - int length = new Random().nextInt(maxlength)+1; StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { // 0-62 (exclusive), random returns 0-61 - int rndCharAt = new Random().nextInt(DATA_FOR_RANDOM_STRING.length()); + int rndCharAt = random.nextInt(DATA_FOR_RANDOM_STRING.length()); char rndChar = DATA_FOR_RANDOM_STRING.charAt(rndCharAt); sb.append(rndChar);