ID: 3528247 - 'lib/ipmi_delloem.c' - fix possible *int flows

Commit fixes possible integer *flows in 'lib/ipmi_delloem.c'. Function
make_int() is removed and replaced with calls to appropriate str2*() function
calls from 'lib/helper.c'.

Reported-by: Duncan Idaho
This commit is contained in:
Zdenek Styblik 2013-03-14 05:33:37 +00:00
parent e320e266b1
commit 4a9af33734

View File

@ -172,7 +172,6 @@ static void ipmi_lcd_usage(void);
/* MAC Function prototypes */ /* MAC Function prototypes */
static int ipmi_delloem_mac_main (struct ipmi_intf * intf, int argc, char ** argv); static int ipmi_delloem_mac_main (struct ipmi_intf * intf, int argc, char ** argv);
static int make_int(const char *str, int *value);
static void InitEmbeddedNICMacAddressValues (); static void InitEmbeddedNICMacAddressValues ();
static int ipmi_macinfo_drac_idrac_virtual_mac(struct ipmi_intf* intf,uint8_t NicNum); static int ipmi_macinfo_drac_idrac_virtual_mac(struct ipmi_intf* intf,uint8_t NicNum);
static int ipmi_macinfo_drac_idrac_mac(struct ipmi_intf* intf,uint8_t NicNum); static int ipmi_macinfo_drac_idrac_mac(struct ipmi_intf* intf,uint8_t NicNum);
@ -390,7 +389,13 @@ static int ipmi_delloem_lcd_main (struct ipmi_intf * intf, int argc, char ** arg
{ {
current_arg++; current_arg++;
if (argc <= current_arg) {usage();return -1;} if (argc <= current_arg) {usage();return -1;}
line_number = (uint8_t)strtoul(argv[current_arg], NULL, 0); if (str2uchar(argv[current_arg], &line_number) != 0)
{
lprintf(LOG_ERR,
"Argument '%s' is either not a number or out of range.\n",
argv[current_arg]);
return (-1);
}
current_arg++; current_arg++;
if (argc <= current_arg) {usage();return -1;} if (argc <= current_arg) {usage();return -1;}
} }
@ -1747,7 +1752,7 @@ static int ipmi_delloem_mac_main (struct ipmi_intf * intf, int argc, char ** arg
return -1; return -1;
} }
if(make_int(argv[current_arg],&currIdInt) < 0) { if(str2int(argv[current_arg],&currIdInt) != 0) {
lprintf(LOG_ERR, "Invalid NIC number. The NIC number should be between 0-8\n"); lprintf(LOG_ERR, "Invalid NIC number. The NIC number should be between 0-8\n");
return -1; return -1;
} }
@ -1765,31 +1770,6 @@ static int ipmi_delloem_mac_main (struct ipmi_intf * intf, int argc, char ** arg
return rc; return rc;
} }
/*****************************************************************
* Function Name: make_int
*
* Description: This function convert string into integer
* Input: str - decimal number string
* Output: value - integer value
* Return:
*
******************************************************************/
static int make_int(const char *str, int *value)
{
char *tmp=NULL;
*value = strtol(str,&tmp,0);
if ( tmp-str != strlen(str) )
{
return -1;
}
return 0;
}
EmbeddedNICMacAddressType EmbeddedNICMacAddress; EmbeddedNICMacAddressType EmbeddedNICMacAddress;
EmbeddedNICMacAddressType_10G EmbeddedNICMacAddress_10G; EmbeddedNICMacAddressType_10G EmbeddedNICMacAddress_10G;
@ -3025,7 +3005,11 @@ static int ipmi_delloem_powermonitor_main (struct ipmi_intf * intf, int argc, ch
lprintf(LOG_ERR, " Cap value in Watts, Btu/hr or percent should be whole number"); lprintf(LOG_ERR, " Cap value in Watts, Btu/hr or percent should be whole number");
return -1; return -1;
} }
make_int(argv[current_arg],&val); if (str2int(argv[current_arg], &val) != 0) {
lprintf(LOG_ERR, "Given capacity value '%s' is invalid.",
argv[current_arg]);
return (-1);
}
current_arg++; current_arg++;
if (argv[current_arg] == NULL) if (argv[current_arg] == NULL)
{ {