diff --git a/fuzzer/Fuzzer.java b/fuzzer/Fuzzer.java index 9394bf8fd81a260984d87d9fe1aa3f3ef35fd4de..abdce166e09cfc94b21575a6b6344bd16b70103a 100644 --- a/fuzzer/Fuzzer.java +++ b/fuzzer/Fuzzer.java @@ -1,38 +1,130 @@ import java.io.IOException; import java.io.FileOutputStream; import java.io.PrintWriter; - +import java.util.Random; /* a stub for your team's fuzzer */ public class Fuzzer { - private static final String OUTPUT_FILE = "fuzz.txt"; - - public static void main(String[] args) throws IOException { - System.out.println(Instruction.getBNF()); - FileOutputStream out = null; - PrintWriter pw = null; - try { - out = new FileOutputStream(OUTPUT_FILE); - pw = new PrintWriter(out); - - /* We just print one instruction. - Hint: you might want to make use of the instruction - grammar which is effectively encoded in Instruction.java */ - pw.println("list"); - - }catch (Exception e){ - e.printStackTrace(System.err); - System.exit(1); - }finally{ - if (pw != null){ - pw.flush(); - } - if (out != null){ - out.close(); - } - } - - } + private static final String OUTPUT_FILE = "fuzz.txt"; + private static Instruction[] INSTRUCTIONS = Instruction.values(); + private static PrintWriter pw = null; + +// private static final int TOTAL_STRATEGY = 30; +// private static final int RANDOM_SEED = 10; + private static final int MAX_LINE_LENGTH = 1022; + private static final int MAX_INSTRUCTIONS = 1024; + + public static void main(String[] args) throws IOException { + System.out.println(Instruction.getBNF()); + int instructionCount = getRandomInt(0, MAX_INSTRUCTIONS); + + FileOutputStream out = null; + PrintWriter pw = null; + + try { + out = new FileOutputStream(OUTPUT_FILE); + pw = new PrintWriter(out); + for (int i = 0; i < instructionCount; i++) { + Instruction instruction = getRandomInstruction(); + String outputString = instruction.getOpcode(); + if (instruction.equals(Instruction.PUSH) || instruction.equals(Instruction.LOAD) + || instruction.equals(Instruction.REM) || instruction.equals(Instruction.STORE)) { + outputString += " "; + outputString += getRandomName(getRandomInt(0, MAX_LINE_LENGTH - outputString.length() - 1)); + } else if (instruction.equals(Instruction.SAVE)) { + outputString += " "; + outputString += getRandomName(getRandomInt(0, MAX_LINE_LENGTH - outputString.length() - 5)); + outputString += ".txt"; + } + pw.println(outputString); + } + + } catch (Exception e) { + e.printStackTrace(System.err); + System.exit(1); + } finally { + if (pw != null) { + pw.flush(); + } + if (out != null) { + out.close(); + } + } + + } + + public static Instruction getRandomInstruction() { + int numInstruction = Instruction.values().length; + int index = getRandomInt(0, numInstruction - 1); + return INSTRUCTIONS[index]; + } + + public static String getRandomName(int maxLenth) { + StringBuffer stringBuffer = new StringBuffer(); + int stringType = getRandomInt(0, 3); + switch (stringType) { + case 0: + for (int i = 0; i < maxLenth; i++) { + int charType = getRandomInt(0, 3); + long asci = 0; + switch (charType) { + case 0: + asci = Math.round(Math.random() * 25 + 65); + if(Math.random()>0.95) + { + asci=32; + } + stringBuffer.append(String.valueOf((char) asci)); + break; + case 1: + asci = Math.round(Math.random() * 25 + 97); + stringBuffer.append(String.valueOf((char) asci)); + break; + case 2: + stringBuffer.append(String.valueOf(getRandomInt(0, 9))); + break; + case 3: + asci = getRandomInt(32, 126); + stringBuffer.append(String.valueOf((char) asci)); + break; + } + + } + break; + case 1: + for (int i = 0; i < maxLenth; i++) { + long asci = 0; + asci = Math.round(Math.random() * 25 + 65); + if(Math.random()>0.95) + { + asci=32; + } + stringBuffer.append(String.valueOf((char) asci)); + } + break; + case 2: + for (int i = 0; i < maxLenth; i++) { + stringBuffer.append(String.valueOf(getRandomInt(0, 9))); + } + break; + case 3: + for (int i = 0; i < maxLenth; i++) { + long asci = 0; + asci = Math.round(Math.random() * 25 + 97); + stringBuffer.append(String.valueOf((char) asci)); + } + break; + default: + break; + } + + return stringBuffer.toString(); + } + + public static int getRandomInt(int min, int max) { + int randomNumber = new Random().nextInt(max + 1 - min) + min; + return randomNumber; + } } diff --git a/src/vuln-1/dc.c b/src/vuln-1/dc.c index 1a47cd0184a07c58217bc2df7304aa3e0d606b5e..63fb7f4f14026c24db10a6f63d0638e7b8c72a57 100644 --- a/src/vuln-1/dc.c +++ b/src/vuln-1/dc.c @@ -146,7 +146,8 @@ static void destroy(node_t *p){ node_t * left = p->left; node_t * const right = p->right; left = node_insert(left,right); - node_free(p); + //node_free(p); + free(p); p = left; } }