Merge "res_http_websocket: Don't leak memory on read failure"

pull/9/head
Jenkins2 8 years ago committed by Gerrit Code Review
commit 71de3deffe

@ -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;
}
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; return -1;
} }
session->payload = new_payload; 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); memcpy(session->payload, &buf[frame_size], *payload_len);
*payload = session->payload; *payload = session->payload;
frame_size += (*payload_len); frame_size += *payload_len;
}
session->closing = 1;
} 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

Loading…
Cancel
Save