Mercurial > dropbear
comparison fuzz-wrapfd.c @ 1528:b9e4fd5a0e72 fuzz
compile fixes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 21 Feb 2018 21:03:42 +0800 |
parents | 4b864fd12b22 |
children | 92c93b4a3646 |
comparison
equal
deleted
inserted
replaced
1512:b024f9695782 | 1528:b9e4fd5a0e72 |
---|---|
2 #include "includes.h" | 2 #include "includes.h" |
3 #include "fuzz-wrapfd.h" | 3 #include "fuzz-wrapfd.h" |
4 | 4 |
5 #include "fuzz.h" | 5 #include "fuzz.h" |
6 | 6 |
7 static const int IOWRAP_MAXFD = FD_SETSIZE-1; | 7 #define IOWRAP_MAXFD (FD_SETSIZE-1) |
8 static const int MAX_RANDOM_IN = 50000; | 8 static const int MAX_RANDOM_IN = 50000; |
9 static const double CHANCE_CLOSE = 1.0 / 300; | 9 static const double CHANCE_CLOSE = 1.0 / 300; |
10 static const double CHANCE_INTR = 1.0 / 200; | 10 static const double CHANCE_INTR = 1.0 / 200; |
11 static const double CHANCE_READ1 = 0.6; | 11 static const double CHANCE_READ1 = 0.6; |
12 static const double CHANCE_READ2 = 0.3; | 12 static const double CHANCE_READ2 = 0.3; |
35 memset(rand_state, 0x0, sizeof(rand_state)); | 35 memset(rand_state, 0x0, sizeof(rand_state)); |
36 wrapfd_setseed(50); | 36 wrapfd_setseed(50); |
37 } | 37 } |
38 | 38 |
39 void wrapfd_setseed(uint32_t seed) { | 39 void wrapfd_setseed(uint32_t seed) { |
40 *((uint32_t*)rand_state) = seed; | 40 memcpy(rand_state, &seed, sizeof(seed)); |
41 nrand48(rand_state); | 41 nrand48(rand_state); |
42 } | 42 } |
43 | 43 |
44 void wrapfd_add(int fd, buffer *buf, enum wrapfd_mode mode) { | 44 void wrapfd_add(int fd, buffer *buf, enum wrapfd_mode mode) { |
45 TRACE(("wrapfd_add %d buf %p mode %d", fd, buf, mode)) | 45 TRACE(("wrapfd_add %d buf %p mode %d", fd, buf, mode)) |
75 } | 75 } |
76 nused--; | 76 nused--; |
77 } | 77 } |
78 | 78 |
79 int wrapfd_close(int fd) { | 79 int wrapfd_close(int fd) { |
80 if (fd >= 0 && fd <= IOWRAP_MAXFD && wrap_fds[fd].mode != UNUSED) | 80 if (fd >= 0 && fd <= IOWRAP_MAXFD && wrap_fds[fd].mode != UNUSED) { |
81 { | |
82 wrapfd_remove(fd); | 81 wrapfd_remove(fd); |
83 return 0; | 82 return 0; |
84 } | 83 } else { |
85 else { | |
86 return close(fd); | 84 return close(fd); |
87 } | 85 } |
88 } | 86 } |
89 | 87 |
90 int wrapfd_read(int fd, void *out, size_t count) { | 88 int wrapfd_read(int fd, void *out, size_t count) { |
171 | 169 |
172 int wrapfd_select(int nfds, fd_set *readfds, fd_set *writefds, | 170 int wrapfd_select(int nfds, fd_set *readfds, fd_set *writefds, |
173 fd_set *exceptfds, struct timeval *timeout) { | 171 fd_set *exceptfds, struct timeval *timeout) { |
174 int i, nset, sel; | 172 int i, nset, sel; |
175 int ret = 0; | 173 int ret = 0; |
176 int fdlist[IOWRAP_MAXFD+1] = {0}; | 174 int fdlist[IOWRAP_MAXFD+1]; |
175 | |
176 memset(fdlist, 0x0, sizeof(fdlist)); | |
177 | 177 |
178 if (!fuzz.wrapfds) { | 178 if (!fuzz.wrapfds) { |
179 return select(nfds, readfds, writefds, exceptfds, timeout); | 179 return select(nfds, readfds, writefds, exceptfds, timeout); |
180 } | 180 } |
181 | 181 |