Skip to content

Commit b6216f0

Browse files
hongzhidaoac000
authored andcommitted
Java: fixed the calculation related to the response buffer.
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: <#923> Reported-by: Alejandro Colomar <[email protected]> Reviewed-by: Andrew Clayton <[email protected]> Signed-off-by: Andrew Clayton <[email protected]>
1 parent 2d0e502 commit b6216f0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/java/nxt_jni_Response.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ nxt_java_get_response_info(jlong req_info_ptr, uint32_t extra_fields,
334334
- req->response->fields_count
335335
|| extra_data > (uint32_t) (buf->end - buf->free))
336336
{
337-
p = buf->start + req->response_max_fields * sizeof(nxt_unit_field_t);
337+
p = buf->start + sizeof(nxt_unit_response_t)
338+
+ req->response_max_fields * sizeof(nxt_unit_field_t);
338339

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

937938
buf = req->response_buf;
938939

939-
buf->free = buf->start + req->response_max_fields
940-
* sizeof(nxt_unit_field_t);
940+
buf->free = buf->start + sizeof(nxt_unit_response_t)
941+
+ req->response_max_fields * sizeof(nxt_unit_field_t);
941942
}
942943
}
943944

src/nxt_unit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,8 @@ nxt_unit_response_realloc(nxt_unit_request_info_t *req,
21482148
resp->status = req->response->status;
21492149
resp->content_length = req->response->content_length;
21502150

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

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

0 commit comments

Comments
 (0)