1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "../SDL_test.h"
#include "fuzzer.h"
//! context for test-specific random number generator
static RND_CTX rndContext;
char *
GenerateExecKey(char *runSeed, char *suiteName,
char *testName, int iterationNumber)
{
if(runSeed == NULL || suiteName == NULL ||
testName == NULL || iterationNumber < 0) {
fprintf(stderr, "Error: Incorrect parameter given to GenerateExecKey function\n");
return NULL;
}
char iterationString[256];
memset(iterationString, 0, sizeof(iterationString));
snprintf(iterationString, sizeof(iterationString), "%d", iterationNumber);
// combine the parameters
const int runSeedLength = strlen(runSeed);
const int suiteNameLength = strlen(suiteName);
const int testNameLength = strlen(testName);
const int iterationStringLength = strlen(iterationString);
// size of the entire + 3 for slashes and + 1 for '\0'
const int entireString = runSeedLength + suiteNameLength +
testNameLength + iterationStringLength + 3 + 1;
char *buffer = SDL_malloc(entireString);
if(!buffer) {
return NULL;
}
SDL_snprintf(buffer, entireString, "%s/%s/%s/%d", runSeed, suiteName,
testName, iterationNumber);
//printf("Debug: %s", buffer);
MD5_CTX md5Context;
utl_md5Init(&md5Context);
utl_md5Update(&md5Context, buffer, entireString);
utl_md5Final(&md5Context);
SDL_free(buffer);
const int keyLength = SDL_strlen(md5Context.digest);
char *key = SDL_malloc(keyLength);
SDL_snprintf(key, keyLength, "%s", md5Context.digest);
return key;
}
void
InitFuzzer(char *execKey)
{
//int a = execKey[8,9,10,11];
int a = execKey[8] | execKey[9] | execKey[10] | execKey[11];
int b = execKey[12] | execKey[13] | execKey[14] | execKey[15];
utl_randomInit(&rndContext, a, b);
}
void
DeinitFuzzer()
{
}
int
RandomInteger()
{
return utl_randomInt(&rndContext);
}
int
RandomPositiveInteger()
{
return abs(utl_randomInt(&rndContext));
}
int
RandomIntegerInRange(int min, int max)
{
if(min > max || (min - max) == 0) {
return -1; // Doesn't really make sense to return -1 on error?
}
int number = utl_randomInt(&rndContext);
number = abs(number);
return (number % ((max + 1) - min)) + min;
}
int
GenerateBoundaryValueForSize(const int size)
{
if(size < 0) {
return -1;
}
const int adjustment = RandomIntegerInRange(-1, 1);
int retValue = (1 << (RandomPositiveInteger() % size)) + adjustment;
return retValue;
}
int
RandomUint8BoundaryValue()
{
return GenerateBoundaryValueForSize(8);
}
int
RandomInt8BoundaryValue()
{
int value = GenerateBoundaryValueForSize(8);
return (RandomPositiveInteger() % 2 == 0 ? value : -value);
}
char *
RandomAsciiString()
{
return RandomAsciiStringWithMaximumLength(255);
}
char *
RandomAsciiStringWithMaximumLength(int maxSize)
{
if(maxSize < 0) {
return NULL;
}
int size = abs(RandomInteger) % maxSize;
char *string = SDL_malloc(size * sizeof(size));
int counter = 0;
for( ; counter < size; ++counter) {
string[counter] = (char) RandomIntegerInRange(1, 127);
}
string[counter] = '\0';
return string;
}