Skip to content

Commit

Permalink
lib: monkey: upgrade to v1.8.1
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Oct 9, 2024
1 parent c7f9150 commit 4feb323
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
5 changes: 5 additions & 0 deletions lib/monkey/include/monkey/mk_http_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,9 @@ int mk_http_parser_chunked_decode(struct mk_http_parser *p,
char *buf_request, size_t buf_request_len,
char **out_buf, size_t *out_buf_size);

int mk_http_parser_chunked_decode_buf(struct mk_http_parser *p,
char *buf_request, size_t buf_request_len,
char *out_buf, size_t out_buf_size, size_t *out_buf_len);


#endif /* MK_HTTP_H */
68 changes: 49 additions & 19 deletions lib/monkey/mk_server/mk_http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,43 +618,73 @@ static int cb_copy_chunk(char *in, size_t in_len, char *out, size_t out_size, si
{
(void) out_size;

/* check we don't overflow the buffer */
if (*out_len_processed + in_len > out_size) {
return -1;
}

/* copy the chunk */
memcpy(out + *out_len_processed, in, in_len);
*out_len_processed += in_len;

return 0;
}

/*
* This function assumes that the output buffer size has enough space to copy the desired
* chunked content. We do some sanity checks but if the buffer is smaller the data will
* be truncated.
*/
int mk_http_parser_chunked_decode_buf(struct mk_http_parser *p,
char *buf_request, size_t buf_request_len,
char *out_buf, size_t out_buf_size, size_t *out_buf_len)
{
int ret;
size_t written_bytes = 0;

ret = mk_http_parser_read_chunked_content(p,
buf_request, buf_request_len,
cb_copy_chunk,
out_buf, out_buf_size, &written_bytes);
if (ret == MK_HTTP_PARSER_OK) {
*out_buf_len = written_bytes;
return 0;
}

return -1;
}

int mk_http_parser_chunked_decode(struct mk_http_parser *p,
char *buf_request, size_t buf_request_len,
char **out_buf, size_t *out_buf_size)
char *buf_request, size_t buf_request_len,
char **out_buf, size_t *out_buf_size)
{
int ret;
size_t size;
size_t tmp = 0;
char *out;
char *tmp_buf;
size_t tmp_buf_size = 0;
size_t tmp_written_bytes = 0;

size = mk_http_parser_content_length(p);
if (size == 0) {
tmp_buf_size = mk_http_parser_content_length(p);
if (tmp_buf_size == 0) {
return -1;
}

out = mk_mem_alloc(size);
if (!out) {
tmp_buf = mk_mem_alloc(tmp_buf_size);
if (!tmp_buf) {
return -1;
}

ret = mk_http_parser_read_chunked_content(p,
buf_request, buf_request_len,
cb_copy_chunk,
out, size, &tmp);
if (ret == MK_HTTP_PARSER_OK) {
*out_buf = out;
*out_buf_size = size;
return 0;
ret = mk_http_parser_chunked_decode_buf(p,
buf_request, buf_request_len,
tmp_buf, tmp_buf_size, &tmp_written_bytes);
if (ret == -1) {
mk_mem_free(tmp_buf);
return -1;
}

mk_mem_free(out);
return -1;
*out_buf = tmp_buf;
*out_buf_size = tmp_written_bytes;

return 0;
}

/*
Expand Down

0 comments on commit 4feb323

Please sign in to comment.