mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
ID: 259 - small memory leak in ipmi_user.c
Commit fixes a small memory leak in 'lib/ipmi_user.c' via strdup(). One typo got fixed in the process.
This commit is contained in:
parent
71dea69efc
commit
2db7f5f6b9
@ -614,28 +614,33 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
char * tmp;
|
char * tmp;
|
||||||
const char * password_prompt =
|
const char * password_prompt =
|
||||||
ipmi_user_build_password_prompt(user_id);
|
ipmi_user_build_password_prompt(user_id);
|
||||||
#ifdef HAVE_GETPASSPHRASE
|
# ifdef HAVE_GETPASSPHRASE
|
||||||
tmp = getpassphrase (password_prompt);
|
tmp = getpassphrase (password_prompt);
|
||||||
#else
|
# else
|
||||||
tmp = (char*)getpass (password_prompt);
|
tmp = (char*)getpass (password_prompt);
|
||||||
#endif
|
# endif
|
||||||
if (tmp != NULL)
|
if (tmp != NULL) {
|
||||||
password = strdup(tmp);
|
password = strdup(tmp);
|
||||||
|
tmp = NULL;
|
||||||
|
}
|
||||||
if (password == NULL) {
|
if (password == NULL) {
|
||||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
password = argv[3];
|
password = strdup(argv[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
retval = ipmi_user_test_password(intf,
|
retval = ipmi_user_test_password(intf,
|
||||||
user_id,
|
user_id,
|
||||||
password,
|
password,
|
||||||
password_length == 20);
|
password_length == 20);
|
||||||
|
if (password != NULL) {
|
||||||
|
free(password);
|
||||||
|
password = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -664,46 +669,42 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
if (argc == 3)
|
if (argc == 3)
|
||||||
{
|
{
|
||||||
/* We need to prompt for a password */
|
/* We need to prompt for a password */
|
||||||
|
|
||||||
char * tmp;
|
char * tmp;
|
||||||
const char * password_prompt =
|
const char * password_prompt =
|
||||||
ipmi_user_build_password_prompt(user_id);
|
ipmi_user_build_password_prompt(user_id);
|
||||||
|
# ifdef HAVE_GETPASSPHRASE
|
||||||
#ifdef HAVE_GETPASSPHRASE
|
|
||||||
tmp = getpassphrase (password_prompt);
|
tmp = getpassphrase (password_prompt);
|
||||||
#else
|
# else
|
||||||
tmp = (char*)getpass (password_prompt);
|
tmp = (char*)getpass (password_prompt);
|
||||||
#endif
|
# endif
|
||||||
if (tmp != NULL)
|
if (tmp != NULL) {
|
||||||
{
|
|
||||||
password = strdup(tmp);
|
password = strdup(tmp);
|
||||||
|
tmp = NULL;
|
||||||
|
}
|
||||||
if (password == NULL) {
|
if (password == NULL) {
|
||||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
# ifdef HAVE_GETPASSPHRASE
|
||||||
#ifdef HAVE_GETPASSPHRASE
|
|
||||||
tmp = getpassphrase (password_prompt);
|
tmp = getpassphrase (password_prompt);
|
||||||
#else
|
# else
|
||||||
tmp = (char*)getpass (password_prompt);
|
tmp = (char*)getpass (password_prompt);
|
||||||
#endif
|
# endif
|
||||||
if (tmp != NULL)
|
if (tmp == NULL) {
|
||||||
{
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
if (strlen(password) != strlen(tmp))
|
return (-1);
|
||||||
{
|
}
|
||||||
lprintf(LOG_ERR, "Passwords do not match");
|
if (strlen(password) != strlen(tmp)
|
||||||
|
|| strncmp(password, tmp, strlen(tmp))) {
|
||||||
|
lprintf(LOG_ERR, "Passwords do not match.");
|
||||||
|
free(password);
|
||||||
|
password = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (strncmp(password, tmp, strlen(tmp)))
|
tmp = NULL;
|
||||||
{
|
} else {
|
||||||
lprintf(LOG_ERR, "Passwords to not match");
|
password = strdup(argv[3]);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
password = argv[3];
|
|
||||||
|
|
||||||
if (password == NULL) {
|
if (password == NULL) {
|
||||||
lprintf(LOG_ERR, "Unable to parse password argument.");
|
lprintf(LOG_ERR, "Unable to parse password argument.");
|
||||||
@ -720,6 +721,10 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
IPMI_PASSWORD_SET_PASSWORD,
|
IPMI_PASSWORD_SET_PASSWORD,
|
||||||
password,
|
password,
|
||||||
strlen(password) > 16);
|
strlen(password) > 16);
|
||||||
|
if (password != NULL) {
|
||||||
|
free(password);
|
||||||
|
password = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user