-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed processing of response body chunks ... #105
Closed
+27
−32
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,10 +163,10 @@ ngx_http_modsecurity_pre_access_handler(ngx_http_request_t *r) | |
|
||
while (chain && !already_inspected) | ||
{ | ||
u_char *data = chain->buf->start; | ||
u_char *data = chain->buf->pos; | ||
|
||
msc_append_request_body(ctx->modsec_transaction, data, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto (it seems like the commit from #104 though, I left the same comment there). |
||
chain->buf->last - chain->buf->pos); | ||
chain->buf->last - data); | ||
|
||
if (chain->buf->last_buf) { | ||
break; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use
ngx_buf_size()
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ngx_buf_size
is defined asIf somehow we happend to receive a
buf
which is completely in a file (i.e., buf->in_file == true but ngx_buf_in_memory(buf) == false) then .pos = .last = 0 but .file_last - .file_post > 0, so we will try to dereference a non-zero length block at NULL pointer .pos. But with current.last - .pos
we would erroneously assume that we have no data but won't segfault at least.But from the other hand I did a quick testing with gdb, even when a response body is buffered to a temporary file, nginx supplies a
buf
which has both.in_file
and.temporary
set (ngx_buf_in_memory(buf) == true
=>.pos
,.last
are valid).ngx_http_charset_filter_module also references .pos/.last in
ngx_http_charset_recode_{to,from}_utf8
without worries . So I think it is guaranteed that response body filters get chain bufs withngx_buf_in_memory(buf) == true
?One more thing, I did a quick grep of Nginx sources and see that ngx_buf_size is not used that much, whereas
.last - .pos
is much more common... maybe we should stick to the latter?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@turchanov well ok - let's keep
.last - .pos
.