mirror of
https://github.com/openappsec/attachment.git
synced 2026-01-02 14:44:42 +03:00
fix send_bodu in lua_attachment_wrapper.c
This commit is contained in:
@@ -363,7 +363,9 @@ static int lua_send_body(lua_State *L) {
|
|||||||
return lua_error(L);
|
return lua_error(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body_len <= 8 * 1024) {
|
// Send the chunk as-is without re-splitting
|
||||||
|
// Kong/Nginx already provides properly sized chunks from ngx.arg[1]
|
||||||
|
// Re-splitting causes memory issues and unnecessary overhead
|
||||||
HttpBody http_chunks;
|
HttpBody http_chunks;
|
||||||
http_chunks.bodies_count = 1;
|
http_chunks.bodies_count = 1;
|
||||||
|
|
||||||
@@ -393,54 +395,6 @@ static int lua_send_body(lua_State *L) {
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t CHUNK_SIZE = 8 * 1024;
|
|
||||||
size_t num_chunks = ((body_len - 1) / CHUNK_SIZE) + 1;
|
|
||||||
|
|
||||||
if (num_chunks > 10000) {
|
|
||||||
num_chunks = 10000;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpBody http_chunks;
|
|
||||||
http_chunks.bodies_count = num_chunks;
|
|
||||||
|
|
||||||
http_chunks.data = (nano_str_t*)malloc(num_chunks * sizeof(nano_str_t));
|
|
||||||
if (!http_chunks.data) {
|
|
||||||
lua_pushstring(L, "Error: Failed to allocate memory for chunks");
|
|
||||||
return lua_error(L);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < num_chunks; i++) {
|
|
||||||
nano_str_t* chunk_ptr = (nano_str_t*)((char*)http_chunks.data + (i * sizeof(nano_str_t)));
|
|
||||||
size_t chunk_start = i * CHUNK_SIZE;
|
|
||||||
size_t chunk_len = (i == num_chunks - 1) ? (body_len - chunk_start) : CHUNK_SIZE;
|
|
||||||
|
|
||||||
chunk_ptr->data = (unsigned char*)(body_chunk + chunk_start);
|
|
||||||
chunk_ptr->len = chunk_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
AttachmentData attachment_data;
|
|
||||||
attachment_data.session_id = session_id;
|
|
||||||
attachment_data.session_data = session_data;
|
|
||||||
attachment_data.chunk_type = chunk_type;
|
|
||||||
attachment_data.data = &http_chunks;
|
|
||||||
|
|
||||||
AttachmentVerdictResponse* res_ptr = malloc(sizeof(AttachmentVerdictResponse));
|
|
||||||
*res_ptr = SendDataNanoAttachment(attachment, &attachment_data);
|
|
||||||
|
|
||||||
free(http_chunks.data);
|
|
||||||
|
|
||||||
lua_pushinteger(L, res_ptr->verdict);
|
|
||||||
lua_pushlightuserdata(L, res_ptr);
|
|
||||||
|
|
||||||
if (res_ptr->modifications) {
|
|
||||||
lua_pushlightuserdata(L, res_ptr->modifications);
|
|
||||||
} else {
|
|
||||||
lua_pushnil(L);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lua_end_inspection(lua_State *L) {
|
static int lua_end_inspection(lua_State *L) {
|
||||||
NanoAttachment* attachment = (NanoAttachment*) lua_touserdata(L, 1);
|
NanoAttachment* attachment = (NanoAttachment*) lua_touserdata(L, 1);
|
||||||
SessionID session_id = luaL_checkinteger(L, 2);
|
SessionID session_id = luaL_checkinteger(L, 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user