diff options
Diffstat (limited to 'lib/ipmi_session.c')
-rw-r--r-- | lib/ipmi_session.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/lib/ipmi_session.c b/lib/ipmi_session.c index 141f0f4..70a3521 100644 --- a/lib/ipmi_session.c +++ b/lib/ipmi_session.c @@ -288,12 +288,12 @@ ipmi_get_session_info(struct ipmi_intf * intf, } rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) + if (!rsp) { lprintf(LOG_ERR, "Get Session Info command failed"); retval = -1; } - else if (rsp->ccode > 0) + else if (rsp->ccode) { lprintf(LOG_ERR, "Get Session Info command failed: %s", val2str(rsp->ccode, completion_code_vals)); @@ -302,15 +302,19 @@ ipmi_get_session_info(struct ipmi_intf * intf, if (retval < 0) { - if ((session_request_type == IPMI_SESSION_REQUEST_CURRENT) && - (strncmp(intf->name, "lan", 3) != 0)) + if (session_request_type == IPMI_SESSION_REQUEST_CURRENT + && strcmp(intf->name, "lan")) + { lprintf(LOG_ERR, "It is likely that the channel in use " "does not support sessions"); + } } else { - memcpy(&session_info, rsp->data, rsp->data_len); - print_session_info(&session_info, rsp->data_len); + memcpy(&session_info, rsp->data, + __min(rsp->data_len, sizeof(session_info))); + print_session_info(&session_info, + __min(rsp->data_len, sizeof(session_info))); } break; @@ -322,13 +326,13 @@ ipmi_get_session_info(struct ipmi_intf * intf, rqdata[0] = i++; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) + if (!rsp) { lprintf(LOG_ERR, "Get Session Info command failed"); retval = -1; break; } - else if (rsp->ccode > 0 && rsp->ccode != 0xCC && rsp->ccode != 0xCB) + else if (rsp->ccode && rsp->ccode != 0xCC && rsp->ccode != 0xCB) { lprintf(LOG_ERR, "Get Session Info command failed: %s", val2str(rsp->ccode, completion_code_vals)); @@ -341,8 +345,10 @@ ipmi_get_session_info(struct ipmi_intf * intf, break; } - memcpy(&session_info, rsp->data, rsp->data_len); - print_session_info(&session_info, rsp->data_len); + memcpy(&session_info, rsp->data, + __min(rsp->data_len, sizeof(session_info))); + print_session_info(&session_info, + __min(rsp->data_len, sizeof(session_info))); } while (i <= session_info.session_slot_count); break; @@ -365,14 +371,14 @@ ipmi_session_main(struct ipmi_intf * intf, int argc, char ** argv) { int retval = 0; - if (argc == 0 || strncmp(argv[0], "help", 4) == 0) + if (!argc || !strcmp(argv[0], "help")) { printf_session_usage(); } - else if (strncmp(argv[0], "info", 4) == 0) + else if (!strcmp(argv[0], "info")) { - if ((argc < 2) || strncmp(argv[1], "help", 4) == 0) + if (argc < 2 || !strcmp(argv[1], "help")) { printf_session_usage(); } @@ -381,11 +387,11 @@ ipmi_session_main(struct ipmi_intf * intf, int argc, char ** argv) Ipmi_Session_Request_Type session_request_type = 0; uint32_t id_or_handle = 0; - if (strncmp(argv[1], "active", 6) == 0) + if (!strcmp(argv[1], "active")) session_request_type = IPMI_SESSION_REQUEST_CURRENT; - else if (strncmp(argv[1], "all", 3) == 0) + else if (!strcmp(argv[1], "all")) session_request_type = IPMI_SESSION_REQUEST_ALL; - else if (strncmp(argv[1], "id", 2) == 0) + else if (!strcmp(argv[1], "id")) { if (argc >= 3) { @@ -404,7 +410,7 @@ ipmi_session_main(struct ipmi_intf * intf, int argc, char ** argv) retval = -1; } } - else if (strncmp(argv[1], "handle", 6) == 0) + else if (!strcmp(argv[1], "handle")) { if (argc >= 3) { |