mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-11 19:17:22 +00:00
fix memory leaks, optimize payload allocator to only allocate what is needed instead of max amount
This commit is contained in:
parent
a292d94239
commit
5298b1ca71
@ -285,6 +285,35 @@ static const struct valstr plus_payload_types_vals[] = {
|
|||||||
{ 0x00, NULL },
|
{ 0x00, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static struct ipmi_rq_entry *
|
||||||
|
ipmi_req_add_entry(struct ipmi_intf * intf, struct ipmi_rq * req)
|
||||||
|
{
|
||||||
|
struct ipmi_rq_entry * e;
|
||||||
|
|
||||||
|
e = malloc(sizeof(struct ipmi_rq_entry));
|
||||||
|
if (e == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(e, 0, sizeof(struct ipmi_rq_entry));
|
||||||
|
memcpy(&e->req, req, sizeof(struct ipmi_rq));
|
||||||
|
|
||||||
|
e->intf = intf;
|
||||||
|
|
||||||
|
if (ipmi_req_entries == NULL)
|
||||||
|
ipmi_req_entries = e;
|
||||||
|
else
|
||||||
|
ipmi_req_entries_tail->next = e;
|
||||||
|
|
||||||
|
ipmi_req_entries_tail = e;
|
||||||
|
lprintf(LOG_DEBUG+3, "added list entry seq=0x%02x cmd=0x%02x",
|
||||||
|
e->rq_seq, e->req.msg.cmd);
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct ipmi_rq_entry *
|
static struct ipmi_rq_entry *
|
||||||
ipmi_req_lookup_entry(uint8_t seq, uint8_t cmd)
|
ipmi_req_lookup_entry(uint8_t seq, uint8_t cmd)
|
||||||
{
|
{
|
||||||
@ -309,8 +338,8 @@ ipmi_req_remove_entry(uint8_t seq, uint8_t cmd)
|
|||||||
e = e->next;
|
e = e->next;
|
||||||
}
|
}
|
||||||
if (e) {
|
if (e) {
|
||||||
if (verbose > 3)
|
lprintf(LOG_DEBUG+3, "removed list entry seq=0x%02x cmd=0x%02x",
|
||||||
printf("removed list entry seq=0x%02x cmd=0x%02x\n", seq, cmd);
|
seq, cmd);
|
||||||
p->next = (p->next == e->next) ? NULL : e->next;
|
p->next = (p->next == e->next) ? NULL : e->next;
|
||||||
if (ipmi_req_entries == e) {
|
if (ipmi_req_entries == e) {
|
||||||
if (ipmi_req_entries != p)
|
if (ipmi_req_entries != p)
|
||||||
@ -324,6 +353,7 @@ ipmi_req_remove_entry(uint8_t seq, uint8_t cmd)
|
|||||||
else
|
else
|
||||||
ipmi_req_entries_tail = NULL;
|
ipmi_req_entries_tail = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e->msg_data)
|
if (e->msg_data)
|
||||||
free(e->msg_data);
|
free(e->msg_data);
|
||||||
free(e);
|
free(e);
|
||||||
@ -337,8 +367,7 @@ ipmi_req_clear_entries(void)
|
|||||||
|
|
||||||
e = ipmi_req_entries;
|
e = ipmi_req_entries;
|
||||||
while (e) {
|
while (e) {
|
||||||
if (verbose > 3)
|
lprintf(LOG_DEBUG+3, "cleared list entry seq=0x%02x cmd=0x%02x",
|
||||||
printf("cleared list entry seq=0x%02x cmd=0x%02x\n",
|
|
||||||
e->rq_seq, e->req.msg.cmd);
|
e->rq_seq, e->req.msg.cmd);
|
||||||
p = e->next;
|
p = e->next;
|
||||||
free(e);
|
free(e);
|
||||||
@ -1399,7 +1428,7 @@ ipmi_lanplus_build_v2x_msg(
|
|||||||
sizeof(rmcp) + // RMCP Header (4)
|
sizeof(rmcp) + // RMCP Header (4)
|
||||||
10 + // IPMI Session Header
|
10 + // IPMI Session Header
|
||||||
2 + // Message length
|
2 + // Message length
|
||||||
IPMI_MAX_PAYLOAD_SIZE + // The actual payload
|
payload->payload_length + // The actual payload
|
||||||
IPMI_MAX_INTEGRITY_PAD_SIZE + // Integrity Pad
|
IPMI_MAX_INTEGRITY_PAD_SIZE + // Integrity Pad
|
||||||
1 + // Pad Length
|
1 + // Pad Length
|
||||||
1 + // Next Header
|
1 + // Next Header
|
||||||
@ -1515,6 +1544,7 @@ ipmi_lanplus_build_v2x_msg(
|
|||||||
default:
|
default:
|
||||||
lprintf(LOG_ERR, "unsupported payload type 0x%x",
|
lprintf(LOG_ERR, "unsupported payload type 0x%x",
|
||||||
payload->payload_type);
|
payload->payload_type);
|
||||||
|
free(msg);
|
||||||
assert(0);
|
assert(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1664,28 +1694,9 @@ ipmi_lanplus_build_v2x_ipmi_cmd(
|
|||||||
if (curr_seq >= 64)
|
if (curr_seq >= 64)
|
||||||
curr_seq = 0;
|
curr_seq = 0;
|
||||||
|
|
||||||
entry = malloc(sizeof(struct ipmi_rq_entry));
|
entry = ipmi_req_add_entry(intf, req);
|
||||||
if (entry == NULL) {
|
if (entry == NULL)
|
||||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
memset(entry, 0, sizeof(struct ipmi_rq_entry));
|
|
||||||
memcpy(&entry->req, req, sizeof(struct ipmi_rq));
|
|
||||||
|
|
||||||
entry->intf = intf;
|
|
||||||
entry->rq_seq = curr_seq;
|
|
||||||
|
|
||||||
// Factor out
|
|
||||||
if (!ipmi_req_entries)
|
|
||||||
ipmi_req_entries = entry;
|
|
||||||
else
|
|
||||||
ipmi_req_entries_tail->next = entry;
|
|
||||||
ipmi_req_entries_tail = entry;
|
|
||||||
|
|
||||||
|
|
||||||
lprintf(LOG_DEBUG+3, "added list entry seq=0x%02x cmd=0x%02x\n",
|
|
||||||
curr_seq, req->msg.cmd);
|
|
||||||
|
|
||||||
|
|
||||||
// Build our payload
|
// Build our payload
|
||||||
v2_payload.payload_type = IPMI_PAYLOAD_TYPE_IPMI;
|
v2_payload.payload_type = IPMI_PAYLOAD_TYPE_IPMI;
|
||||||
@ -1748,23 +1759,9 @@ ipmi_lanplus_build_v15_ipmi_cmd(
|
|||||||
struct ipmi_session * session = intf->session;
|
struct ipmi_session * session = intf->session;
|
||||||
struct ipmi_rq_entry * entry;
|
struct ipmi_rq_entry * entry;
|
||||||
|
|
||||||
entry = malloc(sizeof(struct ipmi_rq_entry));
|
entry = ipmi_req_add_entry(intf, req);
|
||||||
if (entry == NULL) {
|
if (entry == NULL)
|
||||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
memset(entry, 0, sizeof(struct ipmi_rq_entry));
|
|
||||||
memcpy(&entry->req, req, sizeof(struct ipmi_rq));
|
|
||||||
|
|
||||||
entry->intf = intf;
|
|
||||||
|
|
||||||
// Can be factored out
|
|
||||||
if (!ipmi_req_entries)
|
|
||||||
ipmi_req_entries = entry;
|
|
||||||
else
|
|
||||||
ipmi_req_entries_tail->next = entry;
|
|
||||||
|
|
||||||
ipmi_req_entries_tail = entry;
|
|
||||||
|
|
||||||
len = req->msg.data_len + 21;
|
len = req->msg.data_len + 21;
|
||||||
|
|
||||||
@ -2098,8 +2095,13 @@ ipmi_lanplus_send_payload(
|
|||||||
|
|
||||||
|
|
||||||
/* IPMI messages are deleted under ipmi_lan_poll_recv() */
|
/* IPMI messages are deleted under ipmi_lan_poll_recv() */
|
||||||
if (payload->payload_type == IPMI_PAYLOAD_TYPE_SOL)
|
switch (payload->payload_type) {
|
||||||
|
case IPMI_PAYLOAD_TYPE_RMCP_OPEN_REQUEST:
|
||||||
|
case IPMI_PAYLOAD_TYPE_RAKP_1:
|
||||||
|
case IPMI_PAYLOAD_TYPE_RAKP_3:
|
||||||
free(msg_data);
|
free(msg_data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return rsp;
|
return rsp;
|
||||||
}
|
}
|
||||||
@ -2554,6 +2556,7 @@ ipmi_lanplus_open_session(struct ipmi_intf * intf)
|
|||||||
{
|
{
|
||||||
lprintf(LOG_WARNING, "Unsupported cipher suite ID : %d\n",
|
lprintf(LOG_WARNING, "Unsupported cipher suite ID : %d\n",
|
||||||
session->cipher_suite_id);
|
session->cipher_suite_id);
|
||||||
|
free(msg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2601,6 +2604,7 @@ ipmi_lanplus_open_session(struct ipmi_intf * intf)
|
|||||||
|
|
||||||
rsp = ipmi_lanplus_send_payload(intf, &v2_payload);
|
rsp = ipmi_lanplus_send_payload(intf, &v2_payload);
|
||||||
|
|
||||||
|
free(msg);
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
lanplus_dump_open_session_response(rsp);
|
lanplus_dump_open_session_response(rsp);
|
||||||
@ -2730,6 +2734,7 @@ ipmi_lanplus_rakp1(struct ipmi_intf * intf)
|
|||||||
// ERROR;
|
// ERROR;
|
||||||
lprintf(LOG_ERR, "ERROR generating random number "
|
lprintf(LOG_ERR, "ERROR generating random number "
|
||||||
"in ipmi_lanplus_rakp1");
|
"in ipmi_lanplus_rakp1");
|
||||||
|
free(msg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
memcpy(msg + 8, session->v2_data.console_rand, 16);
|
memcpy(msg + 8, session->v2_data.console_rand, 16);
|
||||||
@ -2760,6 +2765,7 @@ ipmi_lanplus_rakp1(struct ipmi_intf * intf)
|
|||||||
lprintf(LOG_ERR, "ERROR: user name too long. "
|
lprintf(LOG_ERR, "ERROR: user name too long. "
|
||||||
"(Exceeds %d characters)",
|
"(Exceeds %d characters)",
|
||||||
IPMI_MAX_USER_NAME_LENGTH);
|
IPMI_MAX_USER_NAME_LENGTH);
|
||||||
|
free(msg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
memcpy(msg + 28, session->username, msg[27]);
|
memcpy(msg + 28, session->username, msg[27]);
|
||||||
@ -2771,6 +2777,8 @@ ipmi_lanplus_rakp1(struct ipmi_intf * intf)
|
|||||||
|
|
||||||
rsp = ipmi_lanplus_send_payload(intf, &v2_payload);
|
rsp = ipmi_lanplus_send_payload(intf, &v2_payload);
|
||||||
|
|
||||||
|
free(msg);
|
||||||
|
|
||||||
if (rsp == NULL)
|
if (rsp == NULL)
|
||||||
{
|
{
|
||||||
lprintf(LOG_INFO, "> Error: no response from RAKP 1 message");
|
lprintf(LOG_INFO, "> Error: no response from RAKP 1 message");
|
||||||
@ -2890,6 +2898,7 @@ ipmi_lanplus_rakp3(struct ipmi_intf * intf)
|
|||||||
{
|
{
|
||||||
/* Error */
|
/* Error */
|
||||||
lprintf(LOG_INFO, "> Error generating RAKP 3 authcode");
|
lprintf(LOG_INFO, "> Error generating RAKP 3 authcode");
|
||||||
|
free(msg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2903,18 +2912,21 @@ ipmi_lanplus_rakp3(struct ipmi_intf * intf)
|
|||||||
{
|
{
|
||||||
/* Error */
|
/* Error */
|
||||||
lprintf(LOG_INFO, "> Error generating session integrity key");
|
lprintf(LOG_INFO, "> Error generating session integrity key");
|
||||||
|
free(msg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (lanplus_generate_k1(session))
|
else if (lanplus_generate_k1(session))
|
||||||
{
|
{
|
||||||
/* Error */
|
/* Error */
|
||||||
lprintf(LOG_INFO, "> Error generating K1 key");
|
lprintf(LOG_INFO, "> Error generating K1 key");
|
||||||
|
free(msg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (lanplus_generate_k2(session))
|
else if (lanplus_generate_k2(session))
|
||||||
{
|
{
|
||||||
/* Error */
|
/* Error */
|
||||||
lprintf(LOG_INFO, "> Error generating K1 key");
|
lprintf(LOG_INFO, "> Error generating K1 key");
|
||||||
|
free(msg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2922,6 +2934,8 @@ ipmi_lanplus_rakp3(struct ipmi_intf * intf)
|
|||||||
|
|
||||||
rsp = ipmi_lanplus_send_payload(intf, &v2_payload);
|
rsp = ipmi_lanplus_send_payload(intf, &v2_payload);
|
||||||
|
|
||||||
|
free(msg);
|
||||||
|
|
||||||
if (session->v2_data.rakp2_return_code != IPMI_RAKP_STATUS_NO_ERRORS)
|
if (session->v2_data.rakp2_return_code != IPMI_RAKP_STATUS_NO_ERRORS)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user