Skip to content

Commit

Permalink
Revert "http: Fix http overflow bug"
Browse files Browse the repository at this point in the history
This reverts commit ea8c1f4.
  • Loading branch information
pymumu committed Aug 27, 2021
1 parent ca6a961 commit f50e4dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 33 deletions.
46 changes: 15 additions & 31 deletions src/http_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -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 {
return -1;
}

if (http_head->expect_data_len == 0) {
http_head->buff_len += process_data_len;
if (http_head->data_len < http_head->expect_data_len) {
return -1;
}

return 0;
return process_data_len;
}

void http_head_destroy(struct http_head *http_head)
Expand Down
2 changes: 0 additions & 2 deletions src/http_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ char *http_head_get_data(struct http_head *http_head);

int http_head_get_data_len(struct http_head *http_head);

int http_head_buff_len(struct http_head *http_head);

struct http_head_fields *http_head_first_fields(struct http_head *http_head);

struct http_head_fields *http_head_next_fields(struct http_head_fields *fields);
Expand Down

0 comments on commit f50e4dd

Please sign in to comment.