diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-05-15 14:32:23 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-05-15 14:32:23 +0300 |
commit | c4b0c4bc95d328f66a0c86544fc2a3b4100fb4d0 (patch) | |
tree | 75da1a4399bf39793159431e5e93c7a2d02bba6a | |
parent | 1ddb4764a7504bda45c1184ca4a2b006f845a6dd (diff) | |
download | libmicrohttpd-c4b0c4bc95d328f66a0c86544fc2a3b4100fb4d0.tar.gz libmicrohttpd-c4b0c4bc95d328f66a0c86544fc2a3b4100fb4d0.zip |
parse_cookie_header(): moved outside error reporting
-rw-r--r-- | src/microhttpd/connection.c | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 949e6ec4..5d795b47 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -2753,12 +2753,22 @@ connection_add_header (struct MHD_Connection *connection, | |||
2753 | 2753 | ||
2754 | 2754 | ||
2755 | /** | 2755 | /** |
2756 | * Cookie parsing result | ||
2757 | */ | ||
2758 | enum _MHD_ParseCookie | ||
2759 | { | ||
2760 | MHD_PARSE_COOKIE_OK = MHD_YES, /**< Success or no cookies in headers */ | ||
2761 | MHD_PARSE_COOKIE_MALFORMED = -1, /**< Invalid cookie header */ | ||
2762 | MHD_PARSE_COOKIE_NO_MEMORY = MHD_NO /**< Not enough memory in the pool */ | ||
2763 | }; | ||
2764 | |||
2765 | /** | ||
2756 | * Parse the cookie header (see RFC 2109). | 2766 | * Parse the cookie header (see RFC 2109). |
2757 | * | 2767 | * |
2758 | * @param connection connection to parse header of | 2768 | * @param connection connection to parse header of |
2759 | * @return #MHD_YES for success, #MHD_NO for failure (malformed, out of memory) | 2769 | * @return #MHD_YES for success, #MHD_NO for failure (malformed, out of memory) |
2760 | */ | 2770 | */ |
2761 | static enum MHD_Result | 2771 | static enum _MHD_ParseCookie |
2762 | parse_cookie_header (struct MHD_Connection *connection) | 2772 | parse_cookie_header (struct MHD_Connection *connection) |
2763 | { | 2773 | { |
2764 | const char *hdr; | 2774 | const char *hdr; |
@@ -2780,20 +2790,12 @@ parse_cookie_header (struct MHD_Connection *connection) | |||
2780 | MHD_HTTP_HEADER_COOKIE), | 2790 | MHD_HTTP_HEADER_COOKIE), |
2781 | &hdr, | 2791 | &hdr, |
2782 | &hdr_len)) | 2792 | &hdr_len)) |
2783 | return MHD_YES; | 2793 | return MHD_PARSE_COOKIE_OK; |
2784 | cpy = connection_alloc_memory (connection, | 2794 | cpy = connection_alloc_memory (connection, |
2785 | hdr_len + 1); | 2795 | hdr_len + 1); |
2786 | if (NULL == cpy) | 2796 | if (NULL == cpy) |
2787 | { | 2797 | return MHD_PARSE_COOKIE_NO_MEMORY; |
2788 | #ifdef HAVE_MESSAGES | 2798 | |
2789 | MHD_DLOG (connection->daemon, | ||
2790 | _ ("Not enough memory in pool to parse cookies!\n")); | ||
2791 | #endif | ||
2792 | transmit_error_response_static (connection, | ||
2793 | MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, | ||
2794 | REQUEST_TOO_BIG); | ||
2795 | return MHD_NO; | ||
2796 | } | ||
2797 | memcpy (cpy, | 2799 | memcpy (cpy, |
2798 | hdr, | 2800 | hdr, |
2799 | hdr_len); | 2801 | hdr_len); |
@@ -2822,13 +2824,13 @@ parse_cookie_header (struct MHD_Connection *connection) | |||
2822 | /* value part omitted, use empty string... */ | 2824 | /* value part omitted, use empty string... */ |
2823 | mhd_assert (ekill >= pos); | 2825 | mhd_assert (ekill >= pos); |
2824 | if (MHD_NO == | 2826 | if (MHD_NO == |
2825 | connection_add_header (connection, | 2827 | MHD_set_connection_value_n_nocheck_ (connection, |
2826 | pos, | 2828 | MHD_COOKIE_KIND, |
2827 | (size_t) (ekill - pos + 1), | 2829 | pos, |
2828 | "", | 2830 | (size_t) (ekill - pos + 1), |
2829 | 0, | 2831 | "", |
2830 | MHD_COOKIE_KIND)) | 2832 | 0)) |
2831 | return MHD_NO; | 2833 | return MHD_PARSE_COOKIE_NO_MEMORY; |
2832 | if (old == '\0') | 2834 | if (old == '\0') |
2833 | break; | 2835 | break; |
2834 | pos = sce + 1; | 2836 | pos = sce + 1; |
@@ -2865,16 +2867,16 @@ parse_cookie_header (struct MHD_Connection *connection) | |||
2865 | mhd_assert (ekill >= pos); | 2867 | mhd_assert (ekill >= pos); |
2866 | mhd_assert (end >= equals); | 2868 | mhd_assert (end >= equals); |
2867 | if (MHD_NO == | 2869 | if (MHD_NO == |
2868 | connection_add_header (connection, | 2870 | MHD_set_connection_value_n_nocheck_ (connection, |
2869 | pos, | 2871 | MHD_COOKIE_KIND, |
2870 | (size_t) (ekill - pos + 1), | 2872 | pos, |
2871 | equals, | 2873 | (size_t) (ekill - pos + 1), |
2872 | (size_t) (end - equals), | 2874 | equals, |
2873 | MHD_COOKIE_KIND)) | 2875 | (size_t) (end - equals))) |
2874 | return MHD_NO; | 2876 | return MHD_PARSE_COOKIE_NO_MEMORY; |
2875 | pos = semicolon; | 2877 | pos = semicolon; |
2876 | } | 2878 | } |
2877 | return MHD_YES; | 2879 | return MHD_PARSE_COOKIE_OK; |
2878 | } | 2880 | } |
2879 | 2881 | ||
2880 | 2882 | ||
@@ -3618,7 +3620,17 @@ parse_connection_headers (struct MHD_Connection *connection) | |||
3618 | const char *enc; | 3620 | const char *enc; |
3619 | size_t val_len; | 3621 | size_t val_len; |
3620 | 3622 | ||
3621 | parse_cookie_header (connection); | 3623 | if (MHD_PARSE_COOKIE_NO_MEMORY == parse_cookie_header (connection)) |
3624 | { | ||
3625 | #ifdef HAVE_MESSAGES | ||
3626 | MHD_DLOG (connection->daemon, | ||
3627 | _ ("Not enough memory in pool to parse cookies!\n")); | ||
3628 | #endif | ||
3629 | transmit_error_response_static (connection, | ||
3630 | MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE, | ||
3631 | REQUEST_TOO_BIG); | ||
3632 | return; | ||
3633 | } | ||
3622 | if ( (1 <= connection->daemon->strict_for_client) && | 3634 | if ( (1 <= connection->daemon->strict_for_client) && |
3623 | (MHD_IS_HTTP_VER_1_1_COMPAT (connection->http_ver)) && | 3635 | (MHD_IS_HTTP_VER_1_1_COMPAT (connection->http_ver)) && |
3624 | (MHD_NO == | 3636 | (MHD_NO == |