| 157 | } |
| 158 | |
| 159 | static htp_connp_t * libhtpFuzzRun(const uint8_t *Data, size_t Size) { |
| 160 | htp_connp_t * connp; |
| 161 | int rc; |
| 162 | test_t test; |
| 163 | |
| 164 | connp = htp_connp_create(cfg); |
| 165 | htp_connp_set_user_data(connp, (void *) 0x02); |
| 166 | htp_connp_open(connp, (const char *) "192.168.2.3", 12345, (const char *) "192.168.2.2", 80, NULL); |
| 167 | |
| 168 | test.buf = (char *)Data; |
| 169 | test.len = Size; |
| 170 | test.pos = 0; |
| 171 | test.chunk = NULL; |
| 172 | |
| 173 | // Find all chunks and feed them to the parser |
| 174 | int in_data_other = 0; |
| 175 | char *in_data = NULL; |
| 176 | size_t in_data_len = 0; |
| 177 | size_t in_data_offset = 0; |
| 178 | int out_data_other = 0; |
| 179 | char *out_data = NULL; |
| 180 | size_t out_data_len = 0; |
| 181 | size_t out_data_offset = 0; |
| 182 | |
| 183 | for (;;) { |
| 184 | if (test_next_chunk(&test) <= 0) { |
| 185 | break; |
| 186 | } |
| 187 | if (test.chunk_len == 0) { |
| 188 | continue; |
| 189 | } |
| 190 | if (test.chunk_direction == CLIENT) { |
| 191 | if (in_data_other) { |
| 192 | break; |
| 193 | } |
| 194 | rc = htp_connp_req_data(connp, NULL, test.chunk, test.chunk_len); |
| 195 | if (rc == HTP_STREAM_ERROR) { |
| 196 | break; |
| 197 | } |
| 198 | if (rc == HTP_STREAM_DATA_OTHER) { |
| 199 | // Parser needs to see the outbound stream in order to continue |
| 200 | // parsing the inbound stream. |
| 201 | in_data_other = 1; |
| 202 | in_data = test.chunk; |
| 203 | in_data_len = test.chunk_len; |
| 204 | in_data_offset = htp_connp_req_data_consumed(connp); |
| 205 | } |
| 206 | } else { |
| 207 | if (out_data_other) { |
| 208 | if (out_data == NULL) { |
| 209 | rc = htp_connp_res_data(connp, NULL, NULL, out_data_len - out_data_offset); |
| 210 | } else { |
| 211 | rc = htp_connp_res_data(connp, NULL, out_data + out_data_offset, out_data_len - out_data_offset); |
| 212 | } |
| 213 | if (rc == HTP_STREAM_ERROR) { |
| 214 | break; |
| 215 | } |
| 216 | out_data_other = 0; |
no test coverage detected