diff options
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r-- | src/microhttpd/connection.c | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index f940145e..60b6931b 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -1091,7 +1091,7 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
1091 | return MHD_NO; | 1091 | return MHD_NO; |
1092 | } | 1092 | } |
1093 | response->data_start = connection->response_write_position; | 1093 | response->data_start = connection->response_write_position; |
1094 | response->data_size = ret; | 1094 | response->data_size = (size_t) ret; |
1095 | if (0 == ret) | 1095 | if (0 == ret) |
1096 | { | 1096 | { |
1097 | connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; | 1097 | connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; |
@@ -1190,12 +1190,14 @@ try_ready_chunked_body (struct MHD_Connection *connection, | |||
1190 | const size_t data_write_offset | 1190 | const size_t data_write_offset |
1191 | = (size_t) (connection->response_write_position - response->data_start); | 1191 | = (size_t) (connection->response_write_position - response->data_start); |
1192 | /* buffer already ready, use what is there for the chunk */ | 1192 | /* buffer already ready, use what is there for the chunk */ |
1193 | ret = response->data_size - data_write_offset; | 1193 | mhd_assert (SSIZE_MAX < (response->data_size - data_write_offset)); |
1194 | mhd_assert (response->data_size >= data_write_offset); | ||
1195 | ret = (ssize_t) (response->data_size - data_write_offset); | ||
1194 | if ( ((size_t) ret) > size_to_fill) | 1196 | if ( ((size_t) ret) > size_to_fill) |
1195 | ret = (ssize_t) size_to_fill; | 1197 | ret = (ssize_t) size_to_fill; |
1196 | memcpy (&connection->write_buffer[max_chunk_hdr_len], | 1198 | memcpy (&connection->write_buffer[max_chunk_hdr_len], |
1197 | &response->data[data_write_offset], | 1199 | &response->data[data_write_offset], |
1198 | ret); | 1200 | (size_t) ret); |
1199 | } | 1201 | } |
1200 | else | 1202 | else |
1201 | { | 1203 | { |
@@ -1263,10 +1265,10 @@ try_ready_chunked_body (struct MHD_Connection *connection, | |||
1263 | chunk_hdr_len); | 1265 | chunk_hdr_len); |
1264 | connection->write_buffer[max_chunk_hdr_len - 2] = '\r'; | 1266 | connection->write_buffer[max_chunk_hdr_len - 2] = '\r'; |
1265 | connection->write_buffer[max_chunk_hdr_len - 1] = '\n'; | 1267 | connection->write_buffer[max_chunk_hdr_len - 1] = '\n'; |
1266 | connection->write_buffer[max_chunk_hdr_len + ret] = '\r'; | 1268 | connection->write_buffer[max_chunk_hdr_len + (size_t) ret] = '\r'; |
1267 | connection->write_buffer[max_chunk_hdr_len + ret + 1] = '\n'; | 1269 | connection->write_buffer[max_chunk_hdr_len + (size_t) ret + 1] = '\n'; |
1268 | connection->response_write_position += ret; | 1270 | connection->response_write_position += (size_t) ret; |
1269 | connection->write_buffer_append_offset = max_chunk_hdr_len + ret + 2; | 1271 | connection->write_buffer_append_offset = max_chunk_hdr_len + (size_t) ret + 2; |
1270 | return MHD_YES; | 1272 | return MHD_YES; |
1271 | } | 1273 | } |
1272 | 1274 | ||
@@ -2138,7 +2140,7 @@ build_header_response (struct MHD_Connection *connection) | |||
2138 | if (buf_size < pos + 5) /* space + code + space */ | 2140 | if (buf_size < pos + 5) /* space + code + space */ |
2139 | return MHD_NO; | 2141 | return MHD_NO; |
2140 | buf[pos++] = ' '; | 2142 | buf[pos++] = ' '; |
2141 | pos += MHD_uint16_to_str (rcode, buf + pos, | 2143 | pos += MHD_uint16_to_str ((uint16_t) rcode, buf + pos, |
2142 | buf_size - pos); | 2144 | buf_size - pos); |
2143 | buf[pos++] = ' '; | 2145 | buf[pos++] = ' '; |
2144 | 2146 | ||
@@ -2819,10 +2821,11 @@ parse_cookie_header (struct MHD_Connection *connection) | |||
2819 | if (old != '=') | 2821 | if (old != '=') |
2820 | { | 2822 | { |
2821 | /* value part omitted, use empty string... */ | 2823 | /* value part omitted, use empty string... */ |
2824 | mhd_assert (ekill >= pos); | ||
2822 | if (MHD_NO == | 2825 | if (MHD_NO == |
2823 | connection_add_header (connection, | 2826 | connection_add_header (connection, |
2824 | pos, | 2827 | pos, |
2825 | ekill - pos + 1, | 2828 | (size_t) (ekill - pos + 1), |
2826 | "", | 2829 | "", |
2827 | 0, | 2830 | 0, |
2828 | MHD_COOKIE_KIND)) | 2831 | MHD_COOKIE_KIND)) |
@@ -2860,12 +2863,14 @@ parse_cookie_header (struct MHD_Connection *connection) | |||
2860 | end--; | 2863 | end--; |
2861 | *end = '\0'; | 2864 | *end = '\0'; |
2862 | } | 2865 | } |
2866 | mhd_assert (ekill >= pos); | ||
2867 | mhd_assert (end >= equals); | ||
2863 | if (MHD_NO == | 2868 | if (MHD_NO == |
2864 | connection_add_header (connection, | 2869 | connection_add_header (connection, |
2865 | pos, | 2870 | pos, |
2866 | ekill - pos + 1, | 2871 | (size_t) (ekill - pos + 1), |
2867 | equals, | 2872 | equals, |
2868 | end - equals, | 2873 | (size_t) (end - equals), |
2869 | MHD_COOKIE_KIND)) | 2874 | MHD_COOKIE_KIND)) |
2870 | return MHD_NO; | 2875 | return MHD_NO; |
2871 | pos = semicolon; | 2876 | pos = semicolon; |
@@ -3057,16 +3062,17 @@ parse_initial_message_line (struct MHD_Connection *connection, | |||
3057 | connection->version = http_version + 1; | 3062 | connection->version = http_version + 1; |
3058 | if (MHD_NO == parse_http_version (connection, connection->version, | 3063 | if (MHD_NO == parse_http_version (connection, connection->version, |
3059 | line_len | 3064 | line_len |
3060 | - (connection->version - line))) | 3065 | - (size_t) |
3066 | (connection->version - line))) | ||
3061 | return MHD_NO; | 3067 | return MHD_NO; |
3062 | uri_len = http_version - uri; | 3068 | uri_len = (size_t) (http_version - uri); |
3063 | } | 3069 | } |
3064 | else | 3070 | else |
3065 | { | 3071 | { |
3066 | connection->version = ""; | 3072 | connection->version = ""; |
3067 | if (MHD_NO == parse_http_version (connection, connection->version, 0)) | 3073 | if (MHD_NO == parse_http_version (connection, connection->version, 0)) |
3068 | return MHD_NO; | 3074 | return MHD_NO; |
3069 | uri_len = line_len - (uri - line); | 3075 | uri_len = line_len - (size_t) (uri - line); |
3070 | } | 3076 | } |
3071 | /* check for spaces in URI if we are "strict" */ | 3077 | /* check for spaces in URI if we are "strict" */ |
3072 | if ( (1 <= daemon->strict_for_client) && | 3078 | if ( (1 <= daemon->strict_for_client) && |
@@ -3845,7 +3851,7 @@ MHD_connection_handle_read (struct MHD_Connection *connection, | |||
3845 | MHD_REQUEST_TERMINATED_WITH_ERROR); | 3851 | MHD_REQUEST_TERMINATED_WITH_ERROR); |
3846 | return; | 3852 | return; |
3847 | } | 3853 | } |
3848 | connection->read_buffer_offset += bytes_read; | 3854 | connection->read_buffer_offset += (size_t) bytes_read; |
3849 | MHD_update_last_activity_ (connection); | 3855 | MHD_update_last_activity_ (connection); |
3850 | #if DEBUG_STATES | 3856 | #if DEBUG_STATES |
3851 | MHD_DLOG (connection->daemon, | 3857 | MHD_DLOG (connection->daemon, |
@@ -3969,7 +3975,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
3969 | (int) ret, | 3975 | (int) ret, |
3970 | &HTTP_100_CONTINUE[connection->continue_message_write_offset]); | 3976 | &HTTP_100_CONTINUE[connection->continue_message_write_offset]); |
3971 | #endif | 3977 | #endif |
3972 | connection->continue_message_write_offset += ret; | 3978 | connection->continue_message_write_offset += (size_t) ret; |
3973 | MHD_update_last_activity_ (connection); | 3979 | MHD_update_last_activity_ (connection); |
3974 | return; | 3980 | return; |
3975 | case MHD_CONNECTION_CONTINUE_SENT: | 3981 | case MHD_CONNECTION_CONTINUE_SENT: |
@@ -4058,10 +4064,10 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4058 | mhd_assert (! connection->rp_props.chunked); | 4064 | mhd_assert (! connection->rp_props.chunked); |
4059 | mhd_assert (connection->rp_props.send_reply_body); | 4065 | mhd_assert (connection->rp_props.send_reply_body); |
4060 | connection->write_buffer_send_offset += wb_ready; | 4066 | connection->write_buffer_send_offset += wb_ready; |
4061 | connection->response_write_position = ret - wb_ready; | 4067 | connection->response_write_position = ((size_t) ret) - wb_ready; |
4062 | } | 4068 | } |
4063 | else | 4069 | else |
4064 | connection->write_buffer_send_offset += ret; | 4070 | connection->write_buffer_send_offset += (size_t) ret; |
4065 | MHD_update_last_activity_ (connection); | 4071 | MHD_update_last_activity_ (connection); |
4066 | if (MHD_CONNECTION_HEADERS_SENDING != connection->state) | 4072 | if (MHD_CONNECTION_HEADERS_SENDING != connection->state) |
4067 | return; | 4073 | return; |
@@ -4142,7 +4148,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4142 | NULL); | 4148 | NULL); |
4143 | return; | 4149 | return; |
4144 | } | 4150 | } |
4145 | connection->response_write_position += ret; | 4151 | connection->response_write_position += (size_t) ret; |
4146 | MHD_update_last_activity_ (connection); | 4152 | MHD_update_last_activity_ (connection); |
4147 | } | 4153 | } |
4148 | if (connection->response_write_position == | 4154 | if (connection->response_write_position == |
@@ -4174,7 +4180,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4174 | NULL); | 4180 | NULL); |
4175 | return; | 4181 | return; |
4176 | } | 4182 | } |
4177 | connection->write_buffer_send_offset += ret; | 4183 | connection->write_buffer_send_offset += (size_t) ret; |
4178 | MHD_update_last_activity_ (connection); | 4184 | MHD_update_last_activity_ (connection); |
4179 | if (MHD_CONNECTION_CHUNKED_BODY_READY != connection->state) | 4185 | if (MHD_CONNECTION_CHUNKED_BODY_READY != connection->state) |
4180 | return; | 4186 | return; |
@@ -4210,7 +4216,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4210 | NULL); | 4216 | NULL); |
4211 | return; | 4217 | return; |
4212 | } | 4218 | } |
4213 | connection->write_buffer_send_offset += ret; | 4219 | connection->write_buffer_send_offset += (size_t) ret; |
4214 | MHD_update_last_activity_ (connection); | 4220 | MHD_update_last_activity_ (connection); |
4215 | if (MHD_CONNECTION_FOOTERS_SENDING != connection->state) | 4221 | if (MHD_CONNECTION_FOOTERS_SENDING != connection->state) |
4216 | return; | 4222 | return; |