|
26 | 26 | #include <errno.h>
|
27 | 27 | #include <poll.h>
|
28 | 28 |
|
29 |
| -extern std::unique_ptr<FuzzedDataProvider> g_fdp; |
30 |
| -extern std::mutex g_fdp_mu; |
| 29 | +std::unique_ptr<FuzzedDataProvider> g_fdp; |
| 30 | +std::mutex g_fdp_mu; |
31 | 31 |
|
32 | 32 | std::string b64encode(const std::string &in) {
|
33 | 33 | static const char* tbl =
|
@@ -80,6 +80,14 @@ std::string safe_ascii(const std::string& in, bool allow_space) {
|
80 | 80 | return out;
|
81 | 81 | }
|
82 | 82 |
|
| 83 | +// Dummy functions |
| 84 | +static enum MHD_Bool kv_cb(void*, enum MHD_ValueKind, const struct MHD_NameAndValue*) { |
| 85 | + return MHD_YES; |
| 86 | +} |
| 87 | +static enum MHD_Bool post_cb(void*, const struct MHD_PostField* pf) { |
| 88 | + return MHD_YES; |
| 89 | +} |
| 90 | + |
83 | 91 | /* Start of internal helpers for sending http message to daemon through localhost socket */
|
84 | 92 | static int create_socket(uint16_t port) {
|
85 | 93 | int fd = socket(AF_INET, SOCK_STREAM, 0);
|
@@ -736,3 +744,58 @@ req_cb(void* cls,
|
736 | 744 | }
|
737 | 745 | return handle_digest_auth(request, opts);
|
738 | 746 | }
|
| 747 | + |
| 748 | +MHD_FN_PAR_NONNULL_(2) MHD_FN_PAR_NONNULL_(3) |
| 749 | +const struct MHD_Action* |
| 750 | +req_cb_stream(void*, |
| 751 | + struct MHD_Request* MHD_RESTRICT request, |
| 752 | + const struct MHD_String* MHD_RESTRICT path, |
| 753 | + enum MHD_HTTP_Method method, |
| 754 | + uint_fast64_t upload_size) { |
| 755 | + // Fuzz MHD_request_get_value for different parameters on random request |
| 756 | + MHD_request_get_value(request, MHD_VK_HEADER, "host"); |
| 757 | + MHD_request_get_value(request, MHD_VK_HEADER, "content-type"); |
| 758 | + MHD_request_get_value(request, MHD_VK_COOKIE, "cookie"); |
| 759 | + MHD_request_get_value(request, MHD_VK_GET_ARGUMENT, "q"); |
| 760 | + MHD_request_get_values_cb(request, MHD_VK_HEADER, kv_cb, nullptr); |
| 761 | + MHD_request_get_values_cb(request, MHD_VK_COOKIE, kv_cb, nullptr); |
| 762 | + MHD_request_get_values_cb(request, MHD_VK_GET_ARGUMENT, kv_cb, nullptr); |
| 763 | + |
| 764 | + // Fuzz MHD_request_get_post_data_cb on random request |
| 765 | + MHD_request_get_post_data_cb(request, post_cb, nullptr); |
| 766 | + |
| 767 | + |
| 768 | + // Fuzz MHD_request_get_info_fixed for different parameters on random request |
| 769 | + union MHD_RequestInfoFixedData fix; |
| 770 | + MHD_request_get_info_fixed(request, MHD_REQUEST_INFO_FIXED_HTTP_VER, &fix); |
| 771 | + MHD_request_get_info_fixed(request, MHD_REQUEST_INFO_FIXED_HTTP_METHOD, &fix); |
| 772 | + MHD_request_get_info_fixed(request, MHD_REQUEST_INFO_FIXED_DAEMON, &fix); |
| 773 | + MHD_request_get_info_fixed(request, MHD_REQUEST_INFO_FIXED_CONNECTION, &fix); |
| 774 | + MHD_request_get_info_fixed(request, MHD_REQUEST_INFO_FIXED_STREAM, &fix); |
| 775 | + MHD_request_get_info_fixed(request, MHD_REQUEST_INFO_FIXED_APP_CONTEXT, &fix); |
| 776 | + |
| 777 | + // Fuzz MHD_request_get_info_dynamic for different parameters on random request |
| 778 | + union MHD_RequestInfoDynamicData dyn; |
| 779 | + MHD_request_get_info_dynamic(request, MHD_REQUEST_INFO_DYNAMIC_HTTP_METHOD_STRING, &dyn); |
| 780 | + MHD_request_get_info_dynamic(request, MHD_REQUEST_INFO_DYNAMIC_URI, &dyn); |
| 781 | + MHD_request_get_info_dynamic(request, MHD_REQUEST_INFO_DYNAMIC_NUMBER_URI_PARAMS, &dyn); |
| 782 | + MHD_request_get_info_dynamic(request, MHD_REQUEST_INFO_DYNAMIC_NUMBER_COOKIES, &dyn); |
| 783 | + MHD_request_get_info_dynamic(request, MHD_REQUEST_INFO_DYNAMIC_HEADER_SIZE, &dyn); |
| 784 | + MHD_request_get_info_dynamic(request, MHD_REQUEST_INFO_DYNAMIC_NUMBER_POST_PARAMS, &dyn); |
| 785 | + MHD_request_get_info_dynamic(request, MHD_REQUEST_INFO_DYNAMIC_UPLOAD_PRESENT, &dyn); |
| 786 | + MHD_request_get_info_dynamic(request, MHD_REQUEST_INFO_DYNAMIC_UPLOAD_CHUNKED, &dyn); |
| 787 | + MHD_request_get_info_dynamic(request, MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TOTAL, &dyn); |
| 788 | + MHD_request_get_info_dynamic(request, MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_RECIEVED, &dyn); |
| 789 | + |
| 790 | + // Fuzz response creation from random request processing |
| 791 | + struct MHD_Response* resp = MHD_response_from_empty(MHD_HTTP_STATUS_NO_CONTENT); |
| 792 | + if (!resp) { |
| 793 | + return MHD_action_abort_request(request); |
| 794 | + } |
| 795 | + |
| 796 | + // Fuzz response and request abortion |
| 797 | + MHD_response_add_header(resp, "x-fuzz", "values"); |
| 798 | + const struct MHD_Action* act = MHD_action_from_response(request, resp); |
| 799 | + MHD_response_destroy(resp); |
| 800 | + return act ? act : MHD_action_abort_request(request); |
| 801 | +} |
0 commit comments