Revert "http: Fix http overflow bug"

This reverts commit ea8c1f47f8.
This commit is contained in:
Nick Peng
2021-08-27 19:14:49 +08:00
parent ca6a9613d9
commit f50e4dd081
2 changed files with 17 additions and 35 deletions

View File

@@ -191,11 +191,6 @@ int http_head_get_data_len(struct http_head *http_head)
return http_head->data_len;
}
int http_head_buff_len(struct http_head *http_head)
{
return http_head->buff_len;
}
static int _http_head_add_fields(struct http_head *http_head, char *name, char *value)
{
unsigned long key = 0;
@@ -377,6 +372,7 @@ int http_head_parse(struct http_head *http_head, const char *data, int data_len)
int i = 0;
char *buff_end = NULL;
int left_size = 0;
int process_data_len = 0;
left_size = http_head->buff_size - http_head->buff_len;
@@ -388,15 +384,18 @@ int http_head_parse(struct http_head *http_head, const char *data, int data_len)
if (http_head->head_ok == 0) {
for (i = 0; i < data_len; i++, data++) {
*(buff_end + i) = *data;
http_head->buff_len++;
if (http_head->buff_len > 1 && *(buff_end + i - 1) == '\r' && *(buff_end + i) == '\n') {
if (http_head->buff_len < 4) {
if (*data == '\n') {
if (http_head->buff_len + i < 2) {
continue;
}
if (*(buff_end + i - 2) == '\n') {
http_head->head_ok = 1;
http_head->head_len = http_head->buff_len + i - 1;
http_head->head_len = http_head->buff_len + i - 2;
i++;
buff_end += i;
data_len -= i;
data++;
if (_http_head_parse(http_head) != 0) {
return -2;
}
@@ -413,51 +412,36 @@ int http_head_parse(struct http_head *http_head, const char *data, int data_len)
return -2;
}
i++;
buff_end += i;
data_len -= i;
data++;
break;
}
}
}
process_data_len += i;
if (http_head->head_ok == 0) {
// Read data again */
http_head->buff_len += process_data_len;
return -1;
}
}
if (http_head->head_ok == 1 && data_len > 0) {
if (http_head->head_ok == 1) {
int get_data_len = (http_head->expect_data_len > data_len) ? data_len : http_head->expect_data_len;
if (http_head->expect_data_len == 0) {
get_data_len = data_len;
}
if (http_head->data == NULL) {
http_head->data = buff_end;
}
memcpy(buff_end, data, get_data_len);
process_data_len += get_data_len;
http_head->data_len += get_data_len;
http_head->buff_len += get_data_len;
if (http_head->expect_data_len > 0) {
http_head->expect_data_len -= get_data_len;
if (http_head->expect_data_len == 0) {
return http_head->buff_len;
}
}
if (http_head->data_len < http_head->expect_data_len) {
return -1;
}
} else {
}
http_head->buff_len += process_data_len;
if (http_head->data_len < http_head->expect_data_len) {
return -1;
}
if (http_head->expect_data_len == 0) {
return -1;
}
return 0;
return process_data_len;
}
void http_head_destroy(struct http_head *http_head)