Skip to content
Snippets Groups Projects
Commit e6d92626 authored by Huyou's avatar Huyou
Browse files

modify vuln5

parent d9ecdf9c
No related branches found
No related tags found
No related merge requests found
Pipeline #58582 passed
......@@ -9,9 +9,6 @@ public class Fuzzer {
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;
......@@ -30,16 +27,25 @@ public class Fuzzer {
String outputString = instruction.getOpcode();
if (instruction.equals(Instruction.PUSH) || instruction.equals(Instruction.LOAD)
|| instruction.equals(Instruction.REM) || instruction.equals(Instruction.STORE)) {
double spaceType = Math.random();
if(spaceType > 0.8){
outputString += "\t";
}else{
outputString += " ";
outputString += getRandomName(getRandomInt(0, MAX_LINE_LENGTH - outputString.length() - 1));
}
outputString += getRandomName(getRandomInt(0, MAX_LINE_LENGTH - outputString.length() - 1), false);
} else if (instruction.equals(Instruction.SAVE)) {
double spaceType = Math.random();
if(spaceType > 0.8){
outputString += "\t";
}else{
outputString += " ";
outputString += getRandomName(getRandomInt(0, MAX_LINE_LENGTH - outputString.length() - 5));
}
outputString += getRandomName(getRandomInt(0, MAX_LINE_LENGTH - outputString.length() - 5), true);
outputString += ".txt";
}
pw.println(outputString);
}
} catch (Exception e) {
e.printStackTrace(System.err);
System.exit(1);
......@@ -60,11 +66,12 @@ public class Fuzzer {
return INSTRUCTIONS[index];
}
public static String getRandomName(int maxLenth) {
public static String getRandomName(int maxLenth, boolean isSAVE) {
StringBuffer stringBuffer = new StringBuffer();
int stringType = getRandomInt(0, 3);
switch (stringType) {
case 0:
//Mix arguments
for (int i = 0; i < maxLenth; i++) {
int charType = getRandomInt(0, 3);
long asci = 0;
......@@ -89,7 +96,6 @@ public class Fuzzer {
stringBuffer.append(String.valueOf((char) asci));
break;
}
}
break;
case 1:
......@@ -104,8 +110,15 @@ public class Fuzzer {
}
break;
case 2:
boolean isFloat = false;
for (int i = 0; i < maxLenth; i++) {
if(Math.random()>0.970 && !isFloat && !isSAVE)
{
stringBuffer.append(".");
isFloat = true;
}
stringBuffer.append(String.valueOf(getRandomInt(0, 9)));
}
break;
case 3:
......
......@@ -75,8 +75,14 @@ static node_t *node_new(const char *varname, const value_t value){
//new->varname = strdup(varname);
/*---- vuln-5 ----*/
new->varname = (char *)malloc(1013 * sizeof(char));
strcpy(new->varname, varname);
char varname_copy[1015] = {};
unsigned int count = 0;
while (varname[count] != '\0') {
varname_copy[count] = varname[count++];
}
new->varname = strdup(varname_copy);
assert(new->varname != NULL && "new: strdup varname failed");
new->value = value;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment