mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-07 02:18:15 +00:00
Merge "res_http_websocket: Don't leak memory on read failure"
This commit is contained in:
@@ -666,18 +666,27 @@ int AST_OPTIONAL_API_NAME(ast_websocket_read)(struct ast_websocket *session, cha
|
|||||||
session->payload_len = 0;
|
session->payload_len = 0;
|
||||||
}
|
}
|
||||||
} else if (*opcode == AST_WEBSOCKET_OPCODE_CLOSE) {
|
} else if (*opcode == AST_WEBSOCKET_OPCODE_CLOSE) {
|
||||||
|
session->closing = 1;
|
||||||
|
|
||||||
/* Make the payload available so the user can look at the reason code if they so desire */
|
/* Make the payload available so the user can look at the reason code if they so desire */
|
||||||
if ((*payload_len) && (new_payload = ast_realloc(session->payload, *payload_len))) {
|
if (!*payload_len) {
|
||||||
if (ws_safe_read(session, &buf[frame_size], (*payload_len), opcode)) {
|
return 0;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
session->payload = new_payload;
|
|
||||||
memcpy(session->payload, &buf[frame_size], *payload_len);
|
|
||||||
*payload = session->payload;
|
|
||||||
frame_size += (*payload_len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
session->closing = 1;
|
if (!(new_payload = ast_realloc(session->payload, *payload_len))) {
|
||||||
|
ast_log(LOG_WARNING, "Failed allocation: %p, %"PRIu64"\n",
|
||||||
|
session->payload, *payload_len);
|
||||||
|
*payload_len = 0;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
session->payload = new_payload;
|
||||||
|
if (ws_safe_read(session, &buf[frame_size], *payload_len, opcode)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memcpy(session->payload, &buf[frame_size], *payload_len);
|
||||||
|
*payload = session->payload;
|
||||||
|
frame_size += *payload_len;
|
||||||
} else {
|
} else {
|
||||||
ast_log(LOG_WARNING, "WebSocket unknown opcode %u\n", *opcode);
|
ast_log(LOG_WARNING, "WebSocket unknown opcode %u\n", *opcode);
|
||||||
/* We received an opcode that we don't understand, the RFC states that 1003 is for a type of data that can't be accepted... opcodes
|
/* We received an opcode that we don't understand, the RFC states that 1003 is for a type of data that can't be accepted... opcodes
|
||||||
|
|||||||
Reference in New Issue
Block a user