mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-11 02:57:22 +00:00
Jan Safranek 1/15/09 sol set parm range checking patch based on Vince Worthington's 8/8/07 patch
This commit is contained in:
parent
c5d1894531
commit
ca90a4b48b
@ -81,6 +81,24 @@ struct activate_payload_rsp {
|
|||||||
#pramga pack(0)
|
#pramga pack(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Small function to validate that user-supplied SOL
|
||||||
|
* configuration parameter values we store in uint8_t
|
||||||
|
* data type falls within valid range. With minval
|
||||||
|
* and maxval parameters we can use the same function
|
||||||
|
* to validate parameters that have different ranges
|
||||||
|
* of values.
|
||||||
|
*
|
||||||
|
* function will return -1 if value is not valid, or
|
||||||
|
* will return 0 if valid.
|
||||||
|
*/
|
||||||
|
int ipmi_sol_set_param_isvalid_uint8_t( const char *strval,
|
||||||
|
const char *name,
|
||||||
|
int base,
|
||||||
|
uint8_t minval,
|
||||||
|
uint8_t maxval,
|
||||||
|
uint8_t *out_value);
|
||||||
|
|
||||||
int ipmi_sol_main(struct ipmi_intf *, int, char **);
|
int ipmi_sol_main(struct ipmi_intf *, int, char **);
|
||||||
int ipmi_get_sol_info(struct ipmi_intf * intf,
|
int ipmi_get_sol_info(struct ipmi_intf * intf,
|
||||||
uint8_t channel,
|
uint8_t channel,
|
||||||
|
@ -632,6 +632,42 @@ ipmi_print_sol_info(struct ipmi_intf * intf, uint8_t channel)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Small function to validate that user-supplied SOL
|
||||||
|
* configuration parameter values we store in uint8_t
|
||||||
|
* data type falls within valid range. With minval
|
||||||
|
* and maxval parameters we can use the same function
|
||||||
|
* to validate parameters that have different ranges
|
||||||
|
* of values.
|
||||||
|
*
|
||||||
|
* function will return -1 if value is not valid, or
|
||||||
|
* will return 0 if valid.
|
||||||
|
*/
|
||||||
|
int ipmi_sol_set_param_isvalid_uint8_t( const char *strval,
|
||||||
|
const char *name,
|
||||||
|
int base,
|
||||||
|
uint8_t minval,
|
||||||
|
uint8_t maxval,
|
||||||
|
uint8_t *out_value)
|
||||||
|
{
|
||||||
|
char *end;
|
||||||
|
long val = strtol(strval, &end, base);
|
||||||
|
|
||||||
|
if ((val < minval)
|
||||||
|
|| (val > maxval)
|
||||||
|
|| (*end != '\0')) {
|
||||||
|
lprintf(LOG_ERR, "Invalid value %s for parameter %s",
|
||||||
|
strval, name);
|
||||||
|
lprintf(LOG_ERR, "Valid values are %d-%d", minval, maxval);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*out_value = val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ipmi_sol_set_param
|
* ipmi_sol_set_param
|
||||||
*
|
*
|
||||||
@ -829,7 +865,10 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
|
|||||||
|
|
||||||
req.msg.data_len = 4;
|
req.msg.data_len = 4;
|
||||||
data[1] = SOL_PARAMETER_CHARACTER_INTERVAL;
|
data[1] = SOL_PARAMETER_CHARACTER_INTERVAL;
|
||||||
data[2] = (uint8_t)strtol(value, NULL, 0);
|
|
||||||
|
/* validate user-supplied input */
|
||||||
|
if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 1, 255, &data[2]))
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* We need other values to complete the request */
|
/* We need other values to complete the request */
|
||||||
if (ipmi_get_sol_info(intf, channel, ¶ms))
|
if (ipmi_get_sol_info(intf, channel, ¶ms))
|
||||||
@ -852,7 +891,10 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
|
|||||||
|
|
||||||
req.msg.data_len = 4;
|
req.msg.data_len = 4;
|
||||||
data[1] = SOL_PARAMETER_CHARACTER_INTERVAL;
|
data[1] = SOL_PARAMETER_CHARACTER_INTERVAL;
|
||||||
data[3] = (uint8_t)strtol(value, NULL, 0);
|
|
||||||
|
/* validate user-supplied input */
|
||||||
|
if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 0, 255, &data[3]))
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* We need other values to complete the request */
|
/* We need other values to complete the request */
|
||||||
if (ipmi_get_sol_info(intf, channel, ¶ms))
|
if (ipmi_get_sol_info(intf, channel, ¶ms))
|
||||||
@ -875,7 +917,10 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
|
|||||||
|
|
||||||
req.msg.data_len = 4;
|
req.msg.data_len = 4;
|
||||||
data[1] = SOL_PARAMETER_SOL_RETRY;
|
data[1] = SOL_PARAMETER_SOL_RETRY;
|
||||||
data[2] = (uint8_t)strtol(value, NULL, 0) & 0x07;
|
|
||||||
|
/* validate user input, 7 is max value */
|
||||||
|
if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 0, 7, &data[2]))
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* We need other values to complete the request */
|
/* We need other values to complete the request */
|
||||||
if (ipmi_get_sol_info(intf, channel, ¶ms))
|
if (ipmi_get_sol_info(intf, channel, ¶ms))
|
||||||
@ -898,7 +943,10 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
|
|||||||
|
|
||||||
req.msg.data_len = 4;
|
req.msg.data_len = 4;
|
||||||
data[1] = SOL_PARAMETER_SOL_RETRY;
|
data[1] = SOL_PARAMETER_SOL_RETRY;
|
||||||
data[3] = (uint8_t)strtol(value, NULL, 0);
|
|
||||||
|
/* validate user-supplied input */
|
||||||
|
if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 0, 255, &data[3]))
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* We need other values to complete the request */
|
/* We need other values to complete the request */
|
||||||
if (ipmi_get_sol_info(intf, channel, ¶ms))
|
if (ipmi_get_sol_info(intf, channel, ¶ms))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user