Skip to content

Commit

Permalink
Fix int overflow (#3346)
Browse files Browse the repository at this point in the history
* Fix int overflow

* Fix typo
  • Loading branch information
twose authored May 26, 2020
1 parent 0e34f0a commit 5f3b600
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions swoole_http_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ using swoole::coroutine::Socket;
zend_class_entry *swoole_http_response_ce;
static zend_object_handlers swoole_http_response_handlers;

static void http_build_header(http_context *, swString *response, int body_length);
static void http_build_header(http_context *, swString *response, size_t body_length);

static inline void http_header_key_format(char *key, int length)
{
Expand Down Expand Up @@ -337,7 +337,7 @@ static PHP_METHOD(swoole_http_response, write)
{
ctx->send_chunked = 1;
swString_clear(http_buffer);
http_build_header(ctx, http_buffer, -1);
http_build_header(ctx, http_buffer, 0);
if (!ctx->send(ctx, http_buffer->str, http_buffer->length))
{
ctx->send_chunked = 0;
Expand Down Expand Up @@ -378,7 +378,7 @@ static PHP_METHOD(swoole_http_response, write)
RETURN_BOOL(ctx->send(ctx, http_buffer->str, http_buffer->length));
}

static void http_build_header(http_context *ctx, swString *response, int body_length)
static void http_build_header(http_context *ctx, swString *response, size_t body_length)
{
char *buf = SwooleTG.buffer_stack->str;
size_t l_buf = SwooleTG.buffer_stack->size;
Expand Down Expand Up @@ -510,6 +510,7 @@ static void http_build_header(http_context *ctx, swString *response, int body_le

if (ctx->send_chunked)
{
SW_ASSERT(body_length == 0);
if (!(header_flag & HTTP_HEADER_TRANSFER_ENCODING))
{
swString_append_ptr(response, ZEND_STRL("Transfer-Encoding: chunked\r\n"));
Expand All @@ -524,7 +525,7 @@ static void http_build_header(http_context *ctx, swString *response, int body_le
body_length = swoole_zlib_buffer->length;
}
#endif
n = sw_snprintf(buf, l_buf, "Content-Length: %d\r\n", body_length);
n = sw_snprintf(buf, l_buf, "Content-Length: %zu\r\n", body_length);
swString_append_ptr(response, buf, n);
}
#ifdef SW_HAVE_COMPRESSION
Expand Down

0 comments on commit 5f3b600

Please sign in to comment.