Skip to content

Commit e7b632c

Browse files
authored
maybe target_size crash (alanxz#837)
* if amq not disconnect when return AMQP_STATUS_BAD_AMQP_DATA, maybe crash in consume_data when next receive data. because it change state->target_size but not allocate state->inbound_buffer. line 222 (bytes_consumed = consume_data(state, &received_data);)
1 parent 9d642be commit e7b632c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

librabbitmq/amqp_connection.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ int amqp_handle_input(amqp_connection_state_t state, amqp_bytes_t received_data,
269269
return AMQP_STATUS_BAD_AMQP_DATA;
270270
}
271271

272-
state->target_size = frame_size + HEADER_SIZE + FOOTER_SIZE;
273-
if ((size_t)state->frame_max < state->target_size) {
272+
frame_size = frame_size + HEADER_SIZE + FOOTER_SIZE;
273+
if ((size_t)state->frame_max < frame_size) {
274274
return AMQP_STATUS_BAD_AMQP_DATA;
275275
}
276276

@@ -279,16 +279,15 @@ int amqp_handle_input(amqp_connection_state_t state, amqp_bytes_t received_data,
279279
return AMQP_STATUS_NO_MEMORY;
280280
}
281281

282-
amqp_pool_alloc_bytes(channel_pool, state->target_size,
283-
&state->inbound_buffer);
282+
amqp_pool_alloc_bytes(channel_pool, frame_size, &state->inbound_buffer);
284283
if (NULL == state->inbound_buffer.bytes) {
285284
return AMQP_STATUS_NO_MEMORY;
286285
}
287286
memcpy(state->inbound_buffer.bytes, state->header_buffer, HEADER_SIZE);
288287
raw_frame = state->inbound_buffer.bytes;
289288

290289
state->state = CONNECTION_STATE_BODY;
291-
290+
state->target_size = frame_size;
292291
bytes_consumed += consume_data(state, &received_data);
293292

294293
/* do we have target_size data yet? if not, return with the

0 commit comments

Comments
 (0)