From d1047eae93484be63aba0bed1a7d5fa92aeafda2 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Thu, 3 May 2018 10:49:36 -0300 Subject: [PATCH] Best practices advices by @defanator on top of #104 --- src/ngx_http_modsecurity_body_filter.c | 3 ++- src/ngx_http_modsecurity_pre_access.c | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ngx_http_modsecurity_body_filter.c b/src/ngx_http_modsecurity_body_filter.c index edf44f6..690190c 100644 --- a/src/ngx_http_modsecurity_body_filter.c +++ b/src/ngx_http_modsecurity_body_filter.c @@ -152,7 +152,8 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { u_char *data = chain->buf->pos; - msc_append_response_body(ctx->modsec_transaction, data, chain->buf->last - data); + msc_append_response_body(ctx->modsec_transaction, data, + ngx_buf_size(chain->buf)); ret = ngx_http_modsecurity_process_intervention(ctx->modsec_transaction, r); if (ret > 0) { return ngx_http_filter_finalize_request(r, diff --git a/src/ngx_http_modsecurity_pre_access.c b/src/ngx_http_modsecurity_pre_access.c index 6f4cbcb..3abfacc 100644 --- a/src/ngx_http_modsecurity_pre_access.c +++ b/src/ngx_http_modsecurity_pre_access.c @@ -131,8 +131,6 @@ ngx_http_modsecurity_pre_access_handler(ngx_http_request_t *r) dd("request body is ready to be processed"); - ngx_chain_t *chain = r->request_body->bufs; - /** * TODO: Speed up the analysis by sending chunk while they arrive. * @@ -161,12 +159,13 @@ ngx_http_modsecurity_pre_access_handler(ngx_http_request_t *r) dd("inspection request body in memory."); } + ngx_chain_t *chain = r->request_body->bufs; while (chain && !already_inspected) { u_char *data = chain->buf->pos; msc_append_request_body(ctx->modsec_transaction, data, - chain->buf->last - data); + ngx_buf_size(chain->buf)); if (chain->buf->last_buf) { break;