-
Notifications
You must be signed in to change notification settings - Fork 6
/
test-float.c
66 lines (49 loc) · 1.55 KB
/
test-float.c
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
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <math.h>
#define bail(msg, pos) \
while (1) { \
\
fprintf(stderr, "%s at %u\n", (char *)msg, (uint32_t)pos); \
return 0; \
\
}
int LLVMFuzzerTestOneInput(uint8_t *buf, size_t len) {
float *p32, lesser, greater;
if (len < 16) bail("too short", 0);
p32 = (float *)(buf);
lesser = 1000000.01;
greater = 1000010.99;
if (*p32 < lesser || *p32 > greater) bail("wrong float", 0);
if (!isnormal(*p32)) bail("not normal", 0);
p32 = (float *)(buf + 4);
lesser = 101.9;
greater = 109.0;
if (*p32 < lesser || *p32 > greater) bail("wrong float", 4);
if (!isnormal(*p32)) bail("not normal", 4);
p32 = (float *)(buf + 8);
lesser = 22222221.9;
greater = 22222225.1;
if (*p32 < lesser || *p32 > greater) bail("wrong float", 8);
if (!isnormal(*p32)) bail("not normal", 8);
abort();
return 0;
}
#ifdef __AFL_COMPILER
int main(int argc, char **argv) {
unsigned char buf[64];
ssize_t len;
int fd = 0;
if (argc > 1) fd = open(argv[1], O_RDONLY);
if ((len = read(fd, buf, sizeof(buf))) <= 0) exit(0);
LLVMFuzzerTestOneInput(buf, len);
exit(0);
}
#endif