mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47: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;
|
||||
|
||||
itr = malloc(sizeof(struct ipmi_sdr_iterator));
|
||||
if (itr == NULL)
|
||||
if (itr == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* get sdr repository info */
|
||||
memset(&req, 0, sizeof(req));
|
||||
@ -1383,8 +1385,10 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header,
|
||||
return NULL;
|
||||
|
||||
data = malloc(len+1);
|
||||
if (data == NULL)
|
||||
if (data == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return NULL;
|
||||
}
|
||||
memset(data, 0, len+1);
|
||||
|
||||
memset(&sdr_rq, 0, sizeof(sdr_rq));
|
||||
@ -1482,8 +1486,10 @@ __sdr_list_add(struct sdr_record_list * head,
|
||||
return -1;
|
||||
|
||||
new = malloc(sizeof(struct sdr_record_list));
|
||||
if (new == NULL)
|
||||
if (new == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return -1;
|
||||
}
|
||||
memcpy(new, entry, sizeof(struct sdr_record_list));
|
||||
|
||||
e = head;
|
||||
@ -1616,8 +1622,10 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf * intf, uint8_t num,
|
||||
struct sdr_record_list * sdrr;
|
||||
|
||||
sdrr = malloc(sizeof(struct sdr_record_list));
|
||||
if (sdrr == NULL)
|
||||
if (sdrr == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
break;
|
||||
}
|
||||
memset(sdrr, 0, sizeof(struct sdr_record_list));
|
||||
sdrr->id = header->id;
|
||||
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;
|
||||
|
||||
head = malloc(sizeof(struct sdr_record_list));
|
||||
if (head == NULL)
|
||||
if (head == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return NULL;
|
||||
}
|
||||
memset(head, 0, sizeof(struct sdr_record_list));
|
||||
|
||||
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;
|
||||
|
||||
sdrr = malloc(sizeof(struct sdr_record_list));
|
||||
if (sdrr == NULL)
|
||||
if (sdrr == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
break;
|
||||
}
|
||||
memset(sdrr, 0, sizeof(struct sdr_record_list));
|
||||
sdrr->id = header->id;
|
||||
sdrr->type = header->type;
|
||||
@ -1848,8 +1860,10 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf * intf, char * id)
|
||||
struct sdr_record_list * sdrr;
|
||||
|
||||
sdrr = malloc(sizeof(struct sdr_record_list));
|
||||
if (sdrr == NULL)
|
||||
if (sdrr == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
break;
|
||||
}
|
||||
memset(sdrr, 0, sizeof(struct sdr_record_list));
|
||||
sdrr->id = header->id;
|
||||
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]))))
|
||||
{
|
||||
*desc = (char *)malloc(strlen(evt->desc) + 32);
|
||||
if (*desc == NULL)
|
||||
if (*desc == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return;
|
||||
}
|
||||
sprintf(*desc, "%s", evt->desc);
|
||||
return;
|
||||
}
|
||||
|
@ -574,6 +574,10 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
#endif
|
||||
if (tmp != NULL)
|
||||
password = strdup(tmp);
|
||||
if (password == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
password = argv[3];
|
||||
@ -632,6 +636,10 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
if (tmp != NULL)
|
||||
{
|
||||
password = strdup(tmp);
|
||||
if (password == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef HAVE_GETPASSPHRASE
|
||||
tmp = getpassphrase (password_prompt);
|
||||
|
@ -116,6 +116,9 @@ void log_init(const char * name, int isdaemon, int verbose)
|
||||
logpriv->name = strdup(name);
|
||||
else
|
||||
logpriv->name = strdup(LOG_NAME_DEFAULT);
|
||||
|
||||
if (logpriv->name == NULL)
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
|
||||
logpriv->daemon = isdaemon;
|
||||
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) {
|
||||
ret = fgets(buf, EXEC_BUF_SIZE, fp);
|
||||
if (!ret)
|
||||
if (ret == NULL)
|
||||
continue;
|
||||
|
||||
/* 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;
|
||||
tok = strtok(ptr, " ");
|
||||
while (tok) {
|
||||
if (__argc < EXEC_ARG_SIZE)
|
||||
if (__argc < EXEC_ARG_SIZE) {
|
||||
__argv[__argc++] = strdup(tok);
|
||||
if (__argv[__argc-1] == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
tok = strtok(NULL, " ");
|
||||
}
|
||||
|
||||
|
@ -428,8 +428,13 @@ main(int argc, char ** argv)
|
||||
* otherwise the default is hardcoded
|
||||
* to use the first entry in the list
|
||||
*/
|
||||
if (intfname == NULL && hostname != NULL)
|
||||
if (intfname == NULL && hostname != NULL) {
|
||||
intfname = strdup("lan");
|
||||
if (intfname == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
goto out_free;
|
||||
}
|
||||
}
|
||||
|
||||
/* load interface */
|
||||
intf = ipmi_intf_load(intfname);
|
||||
|
Loading…
x
Reference in New Issue
Block a user