Mercurial > dropbear
comparison fuzz/fuzz-wrapfd.c @ 1777:97ad26e397a5
Add server postauth fuzzer, wrap connect_remote()
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 13 Nov 2020 23:18:05 +0800 |
parents | d5680e12ac33 |
children | 685b47d8faf7 |
comparison
equal
deleted
inserted
replaced
1776:290caf301a4f | 1777:97ad26e397a5 |
---|---|
33 TRACE(("wrapfd_setup")) | 33 TRACE(("wrapfd_setup")) |
34 | 34 |
35 // clean old ones | 35 // clean old ones |
36 int i; | 36 int i; |
37 for (i = 0; i <= wrapfd_maxfd; i++) { | 37 for (i = 0; i <= wrapfd_maxfd; i++) { |
38 if (wrap_fds[i].mode == COMMONBUF) { | 38 if (wrap_fds[i].mode != UNUSED) { |
39 wrapfd_remove(i); | 39 wrapfd_remove(i); |
40 } | 40 } |
41 } | 41 } |
42 wrapfd_maxfd = -1; | 42 wrapfd_maxfd = -1; |
43 | 43 |
49 void wrapfd_setseed(uint32_t seed) { | 49 void wrapfd_setseed(uint32_t seed) { |
50 memcpy(rand_state, &seed, sizeof(seed)); | 50 memcpy(rand_state, &seed, sizeof(seed)); |
51 nrand48(rand_state); | 51 nrand48(rand_state); |
52 } | 52 } |
53 | 53 |
54 int wrapfd_new() { | 54 int wrapfd_new_fuzzinput() { |
55 if (devnull_fd == -1) { | 55 if (devnull_fd == -1) { |
56 devnull_fd = open("/dev/null", O_RDONLY); | 56 devnull_fd = open("/dev/null", O_RDONLY); |
57 assert(devnull_fd != -1); | 57 assert(devnull_fd != -1); |
58 } | 58 } |
59 | 59 |
66 wrapfd_maxfd = MAX(fd, wrapfd_maxfd); | 66 wrapfd_maxfd = MAX(fd, wrapfd_maxfd); |
67 | 67 |
68 return fd; | 68 return fd; |
69 } | 69 } |
70 | 70 |
71 int wrapfd_new_dummy() { | |
72 if (devnull_fd == -1) { | |
73 devnull_fd = open("/dev/null", O_RDONLY); | |
74 assert(devnull_fd != -1); | |
75 } | |
76 | |
77 int fd = dup(devnull_fd); | |
78 assert(fd != -1); | |
79 assert(wrap_fds[fd].mode == UNUSED); | |
80 wrap_fds[fd].mode = DUMMY; | |
81 wrap_fds[fd].closein = 0; | |
82 wrap_fds[fd].closeout = 0; | |
83 wrapfd_maxfd = MAX(fd, wrapfd_maxfd); | |
84 | |
85 return fd; | |
86 } | |
87 | |
88 | |
71 static void wrapfd_remove(int fd) { | 89 static void wrapfd_remove(int fd) { |
72 TRACE(("wrapfd_remove %d", fd)) | 90 TRACE(("wrapfd_remove %d", fd)) |
73 assert(fd >= 0); | 91 assert(fd >= 0); |
74 assert(fd <= IOWRAP_MAXFD); | 92 assert(fd <= IOWRAP_MAXFD); |
75 assert(wrap_fds[fd].mode != UNUSED); | 93 assert(wrap_fds[fd].mode != UNUSED); |
111 if (erand48(rand_state) < CHANCE_INTR) { | 129 if (erand48(rand_state) < CHANCE_INTR) { |
112 errno = EINTR; | 130 errno = EINTR; |
113 return -1; | 131 return -1; |
114 } | 132 } |
115 | 133 |
116 if (input_buf) { | 134 if (input_buf && wrap_fds[fd].mode == COMMONBUF) { |
117 maxread = MIN(input_buf->len - input_buf->pos, count); | 135 maxread = MIN(input_buf->len - input_buf->pos, count); |
118 /* returns 0 if buf is EOF, as intended */ | 136 /* returns 0 if buf is EOF, as intended */ |
119 if (maxread > 0) { | 137 if (maxread > 0) { |
120 maxread = nrand48(rand_state) % maxread + 1; | 138 maxread = nrand48(rand_state) % maxread + 1; |
121 } | 139 } |
122 memcpy(out, buf_getptr(input_buf, maxread), maxread); | 140 memcpy(out, buf_getptr(input_buf, maxread), maxread); |
123 buf_incrpos(input_buf, maxread); | 141 buf_incrpos(input_buf, maxread); |
124 return maxread; | 142 return maxread; |
125 } | 143 } |
126 | 144 |
145 // return fixed output, of random length | |
127 maxread = MIN(MAX_RANDOM_IN, count); | 146 maxread = MIN(MAX_RANDOM_IN, count); |
128 maxread = nrand48(rand_state) % maxread + 1; | 147 maxread = nrand48(rand_state) % maxread + 1; |
129 memset(out, 0xef, maxread); | 148 memset(out, 0xef, maxread); |
130 return maxread; | 149 return maxread; |
131 } | 150 } |