mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-11 19:17:22 +00:00
check malloc and strdup for success
This commit is contained in:
parent
21837864cc
commit
e72103d30f
@ -1311,8 +1311,10 @@ ipmi_sdr_start(struct ipmi_intf * intf)
|
|||||||
struct sdr_repo_info_rs sdr_info;
|
struct sdr_repo_info_rs sdr_info;
|
||||||
|
|
||||||
itr = malloc(sizeof(struct ipmi_sdr_iterator));
|
itr = malloc(sizeof(struct ipmi_sdr_iterator));
|
||||||
if (itr == NULL)
|
if (itr == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* get sdr repository info */
|
/* get sdr repository info */
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
@ -1383,8 +1385,10 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
data = malloc(len+1);
|
data = malloc(len+1);
|
||||||
if (data == NULL)
|
if (data == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
memset(data, 0, len+1);
|
memset(data, 0, len+1);
|
||||||
|
|
||||||
memset(&sdr_rq, 0, sizeof(sdr_rq));
|
memset(&sdr_rq, 0, sizeof(sdr_rq));
|
||||||
@ -1482,8 +1486,10 @@ __sdr_list_add(struct sdr_record_list * head,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
new = malloc(sizeof(struct sdr_record_list));
|
new = malloc(sizeof(struct sdr_record_list));
|
||||||
if (new == NULL)
|
if (new == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
memcpy(new, entry, sizeof(struct sdr_record_list));
|
memcpy(new, entry, sizeof(struct sdr_record_list));
|
||||||
|
|
||||||
e = head;
|
e = head;
|
||||||
@ -1616,8 +1622,10 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf * intf, uint8_t num,
|
|||||||
struct sdr_record_list * sdrr;
|
struct sdr_record_list * sdrr;
|
||||||
|
|
||||||
sdrr = malloc(sizeof(struct sdr_record_list));
|
sdrr = malloc(sizeof(struct sdr_record_list));
|
||||||
if (sdrr == NULL)
|
if (sdrr == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
memset(sdrr, 0, sizeof(struct sdr_record_list));
|
memset(sdrr, 0, sizeof(struct sdr_record_list));
|
||||||
sdrr->id = header->id;
|
sdrr->id = header->id;
|
||||||
sdrr->type = header->type;
|
sdrr->type = header->type;
|
||||||
@ -1681,8 +1689,10 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf * intf, struct entity_id * entity)
|
|||||||
struct sdr_record_list * head;
|
struct sdr_record_list * head;
|
||||||
|
|
||||||
head = malloc(sizeof(struct sdr_record_list));
|
head = malloc(sizeof(struct sdr_record_list));
|
||||||
if (head == NULL)
|
if (head == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
memset(head, 0, sizeof(struct sdr_record_list));
|
memset(head, 0, sizeof(struct sdr_record_list));
|
||||||
|
|
||||||
if (sdr_list_itr == NULL) {
|
if (sdr_list_itr == NULL) {
|
||||||
@ -1730,8 +1740,10 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf * intf, struct entity_id * entity)
|
|||||||
struct sdr_record_list * sdrr;
|
struct sdr_record_list * sdrr;
|
||||||
|
|
||||||
sdrr = malloc(sizeof(struct sdr_record_list));
|
sdrr = malloc(sizeof(struct sdr_record_list));
|
||||||
if (sdrr == NULL)
|
if (sdrr == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
memset(sdrr, 0, sizeof(struct sdr_record_list));
|
memset(sdrr, 0, sizeof(struct sdr_record_list));
|
||||||
sdrr->id = header->id;
|
sdrr->id = header->id;
|
||||||
sdrr->type = header->type;
|
sdrr->type = header->type;
|
||||||
@ -1848,8 +1860,10 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf * intf, char * id)
|
|||||||
struct sdr_record_list * sdrr;
|
struct sdr_record_list * sdrr;
|
||||||
|
|
||||||
sdrr = malloc(sizeof(struct sdr_record_list));
|
sdrr = malloc(sizeof(struct sdr_record_list));
|
||||||
if (sdrr == NULL)
|
if (sdrr == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
memset(sdrr, 0, sizeof(struct sdr_record_list));
|
memset(sdrr, 0, sizeof(struct sdr_record_list));
|
||||||
sdrr->id = header->id;
|
sdrr->id = header->id;
|
||||||
sdrr->type = header->type;
|
sdrr->type = header->type;
|
||||||
|
@ -126,8 +126,10 @@ ipmi_get_event_desc(struct sel_event_record * rec, char ** desc)
|
|||||||
(evt->data == rec->event_data[1]))))
|
(evt->data == rec->event_data[1]))))
|
||||||
{
|
{
|
||||||
*desc = (char *)malloc(strlen(evt->desc) + 32);
|
*desc = (char *)malloc(strlen(evt->desc) + 32);
|
||||||
if (*desc == NULL)
|
if (*desc == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
sprintf(*desc, "%s", evt->desc);
|
sprintf(*desc, "%s", evt->desc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -574,6 +574,10 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
#endif
|
#endif
|
||||||
if (tmp != NULL)
|
if (tmp != NULL)
|
||||||
password = strdup(tmp);
|
password = strdup(tmp);
|
||||||
|
if (password == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
password = argv[3];
|
password = argv[3];
|
||||||
@ -632,6 +636,10 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
if (tmp != NULL)
|
if (tmp != NULL)
|
||||||
{
|
{
|
||||||
password = strdup(tmp);
|
password = strdup(tmp);
|
||||||
|
if (password == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_GETPASSPHRASE
|
#ifdef HAVE_GETPASSPHRASE
|
||||||
tmp = getpassphrase (password_prompt);
|
tmp = getpassphrase (password_prompt);
|
||||||
|
@ -116,6 +116,9 @@ void log_init(const char * name, int isdaemon, int verbose)
|
|||||||
logpriv->name = strdup(name);
|
logpriv->name = strdup(name);
|
||||||
else
|
else
|
||||||
logpriv->name = strdup(LOG_NAME_DEFAULT);
|
logpriv->name = strdup(LOG_NAME_DEFAULT);
|
||||||
|
|
||||||
|
if (logpriv->name == NULL)
|
||||||
|
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||||
|
|
||||||
logpriv->daemon = isdaemon;
|
logpriv->daemon = isdaemon;
|
||||||
logpriv->level = verbose + LOG_NOTICE;
|
logpriv->level = verbose + LOG_NOTICE;
|
||||||
|
@ -283,7 +283,7 @@ int ipmi_exec_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
|
|
||||||
while (feof(fp) == 0) {
|
while (feof(fp) == 0) {
|
||||||
ret = fgets(buf, EXEC_BUF_SIZE, fp);
|
ret = fgets(buf, EXEC_BUF_SIZE, fp);
|
||||||
if (!ret)
|
if (ret == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* clip off optional comment tail indicated by # */
|
/* clip off optional comment tail indicated by # */
|
||||||
@ -307,8 +307,13 @@ int ipmi_exec_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
__argc = 0;
|
__argc = 0;
|
||||||
tok = strtok(ptr, " ");
|
tok = strtok(ptr, " ");
|
||||||
while (tok) {
|
while (tok) {
|
||||||
if (__argc < EXEC_ARG_SIZE)
|
if (__argc < EXEC_ARG_SIZE) {
|
||||||
__argv[__argc++] = strdup(tok);
|
__argv[__argc++] = strdup(tok);
|
||||||
|
if (__argv[__argc-1] == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
tok = strtok(NULL, " ");
|
tok = strtok(NULL, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,8 +428,13 @@ main(int argc, char ** argv)
|
|||||||
* otherwise the default is hardcoded
|
* otherwise the default is hardcoded
|
||||||
* to use the first entry in the list
|
* to use the first entry in the list
|
||||||
*/
|
*/
|
||||||
if (intfname == NULL && hostname != NULL)
|
if (intfname == NULL && hostname != NULL) {
|
||||||
intfname = strdup("lan");
|
intfname = strdup("lan");
|
||||||
|
if (intfname == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
|
goto out_free;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* load interface */
|
/* load interface */
|
||||||
intf = ipmi_intf_load(intfname);
|
intf = ipmi_intf_load(intfname);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user