mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
fixes minor leaks on command line argument parsing
This commit is contained in:
parent
22b283b210
commit
8882955891
@ -371,6 +371,7 @@ ipmi_main(int argc, char ** argv,
|
|||||||
uint32_t timeout = 0;
|
uint32_t timeout = 0;
|
||||||
int authtype = -1;
|
int authtype = -1;
|
||||||
char * tmp = NULL;
|
char * tmp = NULL;
|
||||||
|
char * tmpe = NULL;
|
||||||
char * hostname = NULL;
|
char * hostname = NULL;
|
||||||
char * username = NULL;
|
char * username = NULL;
|
||||||
char * password = NULL;
|
char * password = NULL;
|
||||||
@ -396,6 +397,8 @@ ipmi_main(int argc, char ** argv,
|
|||||||
{
|
{
|
||||||
switch (argflag) {
|
switch (argflag) {
|
||||||
case 'I':
|
case 'I':
|
||||||
|
if (intfname)
|
||||||
|
free(intfname);
|
||||||
intfname = strdup(optarg);
|
intfname = strdup(optarg);
|
||||||
if (intfname == NULL) {
|
if (intfname == NULL) {
|
||||||
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
||||||
@ -473,6 +476,8 @@ ipmi_main(int argc, char ** argv,
|
|||||||
csv_output = 1;
|
csv_output = 1;
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
|
if (hostname)
|
||||||
|
free(hostname);
|
||||||
hostname = strdup(optarg);
|
hostname = strdup(optarg);
|
||||||
if (hostname == NULL) {
|
if (hostname == NULL) {
|
||||||
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
||||||
@ -488,6 +493,8 @@ ipmi_main(int argc, char ** argv,
|
|||||||
"from file %s", optarg);
|
"from file %s", optarg);
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
|
if (tmp)
|
||||||
|
free(tmp);
|
||||||
#ifdef HAVE_GETPASSPHRASE
|
#ifdef HAVE_GETPASSPHRASE
|
||||||
tmp = getpassphrase("Password: ");
|
tmp = getpassphrase("Password: ");
|
||||||
#else
|
#else
|
||||||
@ -504,6 +511,8 @@ ipmi_main(int argc, char ** argv,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
|
if (kgkey)
|
||||||
|
free(kgkey);
|
||||||
kgkey = strdup(optarg);
|
kgkey = strdup(optarg);
|
||||||
if (kgkey == NULL) {
|
if (kgkey == NULL) {
|
||||||
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
||||||
@ -511,10 +520,10 @@ ipmi_main(int argc, char ** argv,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'K':
|
case 'K':
|
||||||
if ((tmp = getenv("IPMI_KGKEY"))) {
|
if ((tmpe = getenv("IPMI_KGKEY"))) {
|
||||||
if (kgkey)
|
if (kgkey)
|
||||||
free(kgkey);
|
free(kgkey);
|
||||||
kgkey = strdup(tmp);
|
kgkey = strdup(tmpe);
|
||||||
if (kgkey == NULL) {
|
if (kgkey == NULL) {
|
||||||
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
||||||
goto out_free;
|
goto out_free;
|
||||||
@ -524,6 +533,8 @@ ipmi_main(int argc, char ** argv,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
|
if (kgkey)
|
||||||
|
free(kgkey);
|
||||||
kgkey = ipmi_parse_hex(optarg);
|
kgkey = ipmi_parse_hex(optarg);
|
||||||
if (kgkey == NULL) {
|
if (kgkey == NULL) {
|
||||||
goto out_free;
|
goto out_free;
|
||||||
@ -531,14 +542,14 @@ ipmi_main(int argc, char ** argv,
|
|||||||
break;
|
break;
|
||||||
case 'Y':
|
case 'Y':
|
||||||
#ifdef HAVE_GETPASSPHRASE
|
#ifdef HAVE_GETPASSPHRASE
|
||||||
tmp = getpassphrase("Key: ");
|
tmpe = getpassphrase("Key: ");
|
||||||
#else
|
#else
|
||||||
tmp = getpass("Key: ");
|
tmpe = getpass("Key: ");
|
||||||
#endif
|
#endif
|
||||||
if (tmp != NULL) {
|
if (tmpe != NULL) {
|
||||||
if (kgkey)
|
if (kgkey)
|
||||||
free(kgkey);
|
free(kgkey);
|
||||||
kgkey = strdup(tmp);
|
kgkey = strdup(tmpe);
|
||||||
if (kgkey == NULL) {
|
if (kgkey == NULL) {
|
||||||
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
||||||
goto out_free;
|
goto out_free;
|
||||||
@ -546,6 +557,8 @@ ipmi_main(int argc, char ** argv,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
|
if (username)
|
||||||
|
free(username);
|
||||||
if (strlen(optarg) > 16) {
|
if (strlen(optarg) > 16) {
|
||||||
lprintf(LOG_ERR, "Username is too long (> 16 bytes)");
|
lprintf(LOG_ERR, "Username is too long (> 16 bytes)");
|
||||||
goto out_free;
|
goto out_free;
|
||||||
@ -557,6 +570,8 @@ ipmi_main(int argc, char ** argv,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
|
if (sdrcache)
|
||||||
|
free(sdrcache);
|
||||||
sdrcache = strdup(optarg);
|
sdrcache = strdup(optarg);
|
||||||
if (sdrcache == NULL) {
|
if (sdrcache == NULL) {
|
||||||
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
||||||
@ -565,6 +580,8 @@ ipmi_main(int argc, char ** argv,
|
|||||||
break;
|
break;
|
||||||
#ifdef ENABLE_ALL_OPTIONS
|
#ifdef ENABLE_ALL_OPTIONS
|
||||||
case 'o':
|
case 'o':
|
||||||
|
if (oemtype)
|
||||||
|
free(oemtype);
|
||||||
oemtype = strdup(optarg);
|
oemtype = strdup(optarg);
|
||||||
if (oemtype == NULL) {
|
if (oemtype == NULL) {
|
||||||
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
||||||
@ -579,10 +596,14 @@ ipmi_main(int argc, char ** argv,
|
|||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
/* backwards compatible oem hack */
|
/* backwards compatible oem hack */
|
||||||
|
if (oemtype)
|
||||||
|
free(oemtype);
|
||||||
oemtype = strdup("intelwv2");
|
oemtype = strdup("intelwv2");
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
/* backwards compatible oem hack */
|
/* backwards compatible oem hack */
|
||||||
|
if (oemtype)
|
||||||
|
free(oemtype);
|
||||||
oemtype = strdup("supermicro");
|
oemtype = strdup("supermicro");
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
@ -599,19 +620,19 @@ ipmi_main(int argc, char ** argv,
|
|||||||
memset(optarg, 'X', i);
|
memset(optarg, 'X', i);
|
||||||
break;
|
break;
|
||||||
case 'E':
|
case 'E':
|
||||||
if ((tmp = getenv("IPMITOOL_PASSWORD"))) {
|
if ((tmpe = getenv("IPMITOOL_PASSWORD"))) {
|
||||||
if (password)
|
if (password)
|
||||||
free(password);
|
free(password);
|
||||||
password = strdup(tmp);
|
password = strdup(tmpe);
|
||||||
if (password == NULL) {
|
if (password == NULL) {
|
||||||
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((tmp = getenv("IPMI_PASSWORD"))) {
|
else if ((tmpe = getenv("IPMI_PASSWORD"))) {
|
||||||
if (password)
|
if (password)
|
||||||
free(password);
|
free(password);
|
||||||
password = strdup(tmp);
|
password = strdup(tmpe);
|
||||||
if (password == NULL) {
|
if (password == NULL) {
|
||||||
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
||||||
goto out_free;
|
goto out_free;
|
||||||
@ -681,6 +702,8 @@ ipmi_main(int argc, char ** argv,
|
|||||||
sol_escape_char = optarg[0];
|
sol_escape_char = optarg[0];
|
||||||
break;
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
|
if (seloem)
|
||||||
|
free(seloem);
|
||||||
seloem = strdup(optarg);
|
seloem = strdup(optarg);
|
||||||
if (seloem == NULL) {
|
if (seloem == NULL) {
|
||||||
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
lprintf(LOG_ERR, "%s: malloc failure", progname);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user