Skip to content

Commit

Permalink
Java: fixed the calculation related to the response buffer.
Browse files Browse the repository at this point in the history
We need to take into account the size of the nxt_unit_response_t
structure itself when calculating where to start appending data to in
memory.

Closes: <nginx#923>
Reported-by: Alejandro Colomar <[email protected]>
Reviewed-by: Andrew Clayton <[email protected]>
Signed-off-by: Andrew Clayton <[email protected]>
  • Loading branch information
hongzhidao authored and ac000 committed Sep 28, 2023
1 parent 2d0e502 commit b6216f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/java/nxt_jni_Response.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ nxt_java_get_response_info(jlong req_info_ptr, uint32_t extra_fields,
- req->response->fields_count
|| extra_data > (uint32_t) (buf->end - buf->free))
{
p = buf->start + req->response_max_fields * sizeof(nxt_unit_field_t);
p = buf->start + sizeof(nxt_unit_response_t)
+ req->response_max_fields * sizeof(nxt_unit_field_t);

max_size = 2 * (buf->end - p);
if (max_size > nxt_unit_buf_max()) {
Expand Down Expand Up @@ -936,8 +937,8 @@ nxt_java_Response_reset(JNIEnv *env, jclass cls, jlong req_info_ptr)

buf = req->response_buf;

buf->free = buf->start + req->response_max_fields
* sizeof(nxt_unit_field_t);
buf->free = buf->start + sizeof(nxt_unit_response_t)
+ req->response_max_fields * sizeof(nxt_unit_field_t);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/nxt_unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,8 @@ nxt_unit_response_realloc(nxt_unit_request_info_t *req,
resp->status = req->response->status;
resp->content_length = req->response->content_length;

p = buf->start + max_fields_count * sizeof(nxt_unit_field_t);
p = buf->start + sizeof(nxt_unit_response_t)
+ max_fields_count * sizeof(nxt_unit_field_t);
f = resp->fields;

for (i = 0; i < req->response->fields_count; i++) {
Expand Down

0 comments on commit b6216f0

Please sign in to comment.